A - Rated for Me


Time Limit: 2 sec / Memory Limit: 1024 MB

Score : 100 points

Problem Statement

A programming competition site AtCode regularly holds programming contests.

The next contest on AtCode is called ABC, which is rated for contestants with ratings less than 1200.

The contest after the ABC is called ARC, which is rated for contestants with ratings less than 2800.

The contest after the ARC is called AGC, which is rated for all contestants.

Takahashi's rating on AtCode is R. What is the next contest rated for him?

Constraints

  • 0≤R≤4208
  • R is an integer.

Input

Input is given from Standard Input in the following format:

R

Output

Print the name of the next contest rated for Takahashi (ABCARC or AGC).


Sample Input 1 Copy

Copy
1199

Sample Output 1 Copy

Copy
ABC

1200, so ABC will be rated.


Sample Input 2 Copy

Copy
1200

Sample Output 2 Copy

Copy
ARC

2800 and ARC will be rated.


Sample Input 3 Copy

Copy
4208

Sample Output 3 Copy

Copy
AGC
代码:
import java.util.*;

public class Main {
    
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        int n = in.nextInt();
        if(n < 1200)System.out.println("ABC");
        else if(n < 2800)System.out.println("ARC");
        else System.out.println("AGC");
    }
}

B - AcCepted


Time Limit: 2 sec / Memory Limit: 1024 MB

Score : 200 points

Problem Statement

You are given a string S satisfies all of the following conditions:

  • The initial character of S is an uppercase A.
  • There is exactly one occurrence of C between the third character from the beginning and the second to last character (inclusive).
  • All letters except the A and C mentioned above are lowercase.

Constraints

  • S.)
  • Each character of S is uppercase or lowercase English letter.

Input

Input is given from Standard Input in the following format:

S

Output

If S satisfies all of the conditions in the problem statement, print AC; otherwise, print WA.


Sample Input 1 Copy

Copy
AtCoder

Sample Output 1 Copy

Copy
AC

The first letter is A, the third letter is C and the remaining letters are all lowercase, so all the conditions are satisfied.


Sample Input 2 Copy

Copy
ACoder

Sample Output 2 Copy

Copy
WA

The second letter should not be C.


Sample Input 3 Copy

Copy
AcycliC

Sample Output 3 Copy

Copy
WA

The last letter should not be C, either.


Sample Input 4 Copy

Copy
AtCoCo

Sample Output 4 Copy

Copy
WA

There should not be two or more occurrences of C.


Sample Input 5 Copy

Copy
Atcoder

Sample Output 5 Copy

Copy
WA

The number of C should not be zero, either.

代码:

import java.util.*;

public class Main {
    static boolean check(String s) {
        if(s.charAt(0) != 'A')return false;
        boolean flag = false;
        for(int i = 1;i < s.length();i ++) {
            if(s.charAt(i) != 'C') {
                if(s.charAt(i) >= 'A' && s.charAt(i) <= 'Z')return false;
            }
            else if(flag || i < 2 || s.length() - i < 2)return false;
            else flag = true;
        }
        return flag;
    }
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        String s = in.nextLine();
        if(check(s)) {
            System.out.println("AC");
        }
        else {
            System.out.println("WA");
        }
    }
}

C - All Green


Time Limit: 2 sec / Memory Limit: 1024 MB

Score : 300 points

Problem Statement

A programming competition site AtCode provides algorithmic problems. Each problem is allocated a score based on its difficulty. Currently, for each integer p1+…+pD problems are all of the problems available on AtCode.

A user of AtCode has a value called total score. The total score of a user is the sum of the following two elements:

  • Base score: the sum of the scores of all problems solved by the user.
  • Perfect bonuses: when a user solves all problems with a score of (1≤i≤D).

Takahashi, who is the new user of AtCode, has not solved any problem. His objective is to have a total score of G or more points. At least how many problems does he need to solve for this objective?

Constraints

  • 1≤D≤10
  • 1≤pi≤100
  • 100≤ci≤106
  • 100≤G
  • All values in input are integers.
  • 100.
  • It is possible to have a total score of G or more points.

Input

Input is given from Standard Input in the following format:

G
c1
:
cD

Output

Print the minimum number of problems that needs to be solved in order to have a total score of G or more points. Note that this objective is always achievable (see Constraints).


Sample Input 1 Copy

Copy
2 700
3 500
5 800

Sample Output 1 Copy

Copy
3

In this case, there are three problems each with 700 points or more.

One way to achieve this objective is to solve four 800 points, and we can achieve the objective with fewer problems.


Sample Input 2 Copy

Copy
2 2000
3 500
5 800

Sample Output 2 Copy

Copy
7

This case is similar to Sample Input 1, but the Takahashi's objective this time is 2000 points.


Sample Input 3 Copy

Copy
2 400
3 500
5 800

Sample Output 3 Copy

Copy
2

This case is again similar to Sample Input 1, but the Takahashi's objective this time is 200-point problems to achieve the objective.


Sample Input 4 Copy

Copy
5 25000
20 1000
40 1000
50 1000
30 1000
1 1000

Sample Output 4 Copy

Copy
66

There is only one 500-point problem, but the perfect bonus can be earned even in such a case.

 

可以dfs遍历所有的情况,直到大于等于所需要的为止。

代码:

#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<algorithm>
#define Max 100001
#define inf 1000000000000000
using namespace std;
struct title {
    int p,c,score;
}s[11];
int d,g,ans = 1000;
int vis[11];
void dfs(int sum,int k) {
    for(int i = 1;i <= d;i ++) {
        if(vis[i])continue;
        if(g - sum <= s[i].score) {
            int temp;
            if(g - sum < s[i].p * i) {
                temp = g - sum;
                temp = temp / i + (temp % i > 0);
            }
            else temp = s[i].p;
            ans = min(ans,k + temp);
            continue;
        }
        vis[i] = 1;
        dfs(sum + s[i].score,k + s[i].p);
        vis[i] = 0;
    }
}
int main() {
    scanf("%d%d",&d,&g);
    g /= 100;
    for(int i = 1;i <= d;i ++) {
        scanf("%d%d",&s[i].p,&s[i].c);
        s[i].c /= 100;
        s[i].score = s[i].p * i + s[i].c;
    }
    dfs(0,0);
    printf("%d",ans);
}

因为最多十种题目,可以用二进制位存状态,遍历各种情况。

代码:

#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<algorithm>
#define Max 100001
#define inf 1000000000000000
using namespace std;
struct problem {
    int p,c,score;
}s[11];
int d,g,ans = 1000;

int main() {
    scanf("%d%d",&d,&g);
    g /= 100;
    for(int i = 1;i <= d;i ++) {
        scanf("%d%d",&s[i].p,&s[i].c);
        s[i].c /= 100;
        s[i].score = s[i].p * i + s[i].c;
    }
    for(int i = 1;i < 1 << (d + 1);i ++) {
        int sum = 0,k = 0,maxn;
        for(int j = 1;j <= d;j ++) {
            if(i & (1 << j)) {
                sum += s[j].score;
                k += s[j].p;
            }
            else maxn = j;
        }
        if(sum < g) {
            int need = (g - sum + maxn - 1) / maxn;
            if(need > s[maxn].p)continue;
            k += need;
        }
        ans = min(ans,k);
    }
    printf("%d",ans);
}

D - We Love ABC


Time Limit: 2 sec / Memory Limit: 1024 MB

Score : 400 points

Problem Statement

The ABC number of a string (i,j,k) that satisfy all of the following conditions:

  • T.)
  • T from the beginning.)
  • Tj= B
  • Tk= C

For example, when 3.

You are given a string S is ABC or ?.

Let S with AB or C. Find the sum of the ABC numbers of all these strings.

This sum can be extremely large, so print the sum modulo 109+7.

Constraints

  • 3≤|S|≤105
  • Each character of S is ABC or ?.

Input

Input is given from Standard Input in the following format:

S

Output

Print the sum of the ABC numbers of all the 109+7.


Sample Input 1 Copy

Copy
A??C

Sample Output 1 Copy

Copy
8

In this case, 3Q=9 strings by by replacing each occurrence of ? with AB or C. The ABC number of each of these strings is as follows:

  • AAAC0
  • AABC2
  • AACC0
  • ABAC1
  • ABBC2
  • ABCC2
  • ACAC0
  • ACBC1
  • ACCC0

The sum of these is 8.


Sample Input 2 Copy

Copy
ABCBC

Sample Output 2 Copy

Copy
3

When 3.


Sample Input 3 Copy

Copy
????C?????B??????A???????

Sample Output 3 Copy

Copy
979596887

In this case, the sum of the ABC numbers of all the 979596887.

动态规划。

#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<algorithm>
#define Max 100005
using namespace std;
typedef long long LL;
const int Mod = 1000000007;
char s[Max];
LL dp[4][Max];///0 '?' 1 'A' 2 'AB' 3 'ABC'
int a,b;
int main() {
    scanf("%s",s + 1);
    dp[0][0] = 1;///初始为1
    int n = strlen(s + 1);
    for(int i = 1;i <= n;i ++) {
        for(int j = 0;j <= 3;j ++) {
            dp[j][i] = dp[j][i - 1];///加上之前的
            if(s[i] == '?')dp[j][i] = (dp[j][i] * 3) % Mod;///如果是问号 有三种选择
            if(j && (s[i] == '?' || s[i] - 'A' + 1 == j)) {///如果对应于匹配位置
                dp[j][i] = (dp[j][i] + dp[j - 1][i - 1]) % Mod;
            }
        }
    }
    printf("%lld",dp[3][n]);
}

 

相关文章: