AtCoder Beginner Contest 104
A - Rated for Me
Time Limit: 2 sec / Memory Limit: 1024 MB
Score : 100100 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 12001200.
The contest after the ABC is called ARC, which is rated for contestants with ratings less than 28002800.
The contest after the ARC is called AGC, which is rated for all contestants.
Takahashi's rating on AtCode is RR. What is the next contest rated for him?
Constraints
- 0≤R≤42080≤R≤4208
- RR is an integer.
Input
Input is given from Standard Input in the following format:
RR
Output
Print the name of the next contest rated for Takahashi (ABC, ARC or AGC).
Sample Input 1 Copy
1199
Sample Output 1 Copy
ABC
11991199 is less than 12001200, so ABC will be rated.
Sample Input 2 Copy
1200
Sample Output 2 Copy
ARC
12001200 is not less than 12001200 and ABC will be unrated, but it is less than 28002800 and ARC will be rated.
Sample Input 3 Copy
4208
Sample Output 3 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 : 200200 points
Problem Statement
You are given a string SS. Each character of SS is uppercase or lowercase English letter. Determine if SS satisfies all of the following conditions:
- The initial character of SS is an uppercase
A. - There is exactly one occurrence of
Cbetween the third character from the beginning and the second to last character (inclusive). - All letters except the
AandCmentioned above are lowercase.
Constraints
- 4≤|S|≤104≤|S|≤10 (|S||S| is the length of the string SS.)
- Each character of SS is uppercase or lowercase English letter.
Input
Input is given from Standard Input in the following format:
SS
Output
If SS satisfies all of the conditions in the problem statement, print AC; otherwise, print WA.
Sample Input 1 Copy
AtCoder
Sample Output 1 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
ACoder
Sample Output 2 Copy
WA
The second letter should not be C.
Sample Input 3 Copy
AcycliC
Sample Output 3 Copy
WA
The last letter should not be C, either.
Sample Input 4 Copy
AtCoCo
Sample Output 4 Copy
WA
There should not be two or more occurrences of C.
Sample Input 5 Copy
Atcoder
Sample Output 5 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 : 300300 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 iibetween 11 and DD (inclusive), there are pipi problems with a score of 100i100i points. These p1+…+pDp1+…+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 100i100i points, he/she earns the perfect bonus of cici points, aside from the base score (1≤i≤D)(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 GG or more points. At least how many problems does he need to solve for this objective?
Constraints
- 1≤D≤101≤D≤10
- 1≤pi≤1001≤pi≤100
- 100≤ci≤106100≤ci≤106
- 100≤G100≤G
- All values in input are integers.
- cici and GG are all multiples of 100100.
- It is possible to have a total score of GG or more points.
Input
Input is given from Standard Input in the following format:
DD GG
p1p1 c1c1
::
pDpD cDcD
Output
Print the minimum number of problems that needs to be solved in order to have a total score of GG or more points. Note that this objective is always achievable (see Constraints).
Sample Input 1 Copy
2 700
3 500
5 800
Sample Output 1 Copy
3
In this case, there are three problems each with 100100 points and five problems each with 200200 points. The perfect bonus for solving all the 100100-point problems is 500500 points, and the perfect bonus for solving all the 200200-point problems is 800800 points. Takahashi's objective is to have a total score of 700700 points or more.
One way to achieve this objective is to solve four 200200-point problems and earn a base score of 800800 points. However, if we solve three 100100-point problems, we can earn the perfect bonus of 500500 points in addition to the base score of 300300 points, for a total score of 800800 points, and we can achieve the objective with fewer problems.
Sample Input 2 Copy
2 2000
3 500
5 800
Sample Output 2 Copy
7
This case is similar to Sample Input 1, but the Takahashi's objective this time is 20002000 points or more. In this case, we inevitably need to solve all five 200200-point problems, and by solving two 100100-point problems additionally we have the total score of 20002000 points.
Sample Input 3 Copy
2 400
3 500
5 800
Sample Output 3 Copy
2
This case is again similar to Sample Input 1, but the Takahashi's objective this time is 400400 points or more. In this case, we only need to solve two 200200-point problems to achieve the objective.
Sample Input 4 Copy
5 25000
20 1000
40 1000
50 1000
30 1000
1 1000
Sample Output 4 Copy
66
There is only one 500500-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[];
int d,g,ans = ;
int vis[];
void dfs(int sum,int k) {
for(int i = ;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 > );
}
else temp = s[i].p;
ans = min(ans,k + temp);
continue;
}
vis[i] = ;
dfs(sum + s[i].score,k + s[i].p);
vis[i] = ;
}
}
int main() {
scanf("%d%d",&d,&g);
g /= ;
for(int i = ;i <= d;i ++) {
scanf("%d%d",&s[i].p,&s[i].c);
s[i].c /= ;
s[i].score = s[i].p * i + s[i].c;
}
dfs(,);
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[];
int d,g,ans = ; int main() {
scanf("%d%d",&d,&g);
g /= ;
for(int i = ;i <= d;i ++) {
scanf("%d%d",&s[i].p,&s[i].c);
s[i].c /= ;
s[i].score = s[i].p * i + s[i].c;
}
for(int i = ;i < << (d + );i ++) {
int sum = ,k = ,maxn;
for(int j = ;j <= d;j ++) {
if(i & ( << j)) {
sum += s[j].score;
k += s[j].p;
}
else maxn = j;
}
if(sum < g) {
int need = (g - sum + maxn - ) / 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 : 400400 points
Problem Statement
The ABC number of a string TT is the number of triples of integers (i,j,k)(i,j,k) that satisfy all of the following conditions:
- 1≤i<j<k≤|T|1≤i<j<k≤|T| (|T||T| is the length of TT.)
- Ti=Ti=
A(TiTi is the ii-th character of TT from the beginning.) - Tj=Tj=
B - Tk=Tk=
C
For example, when T=T= ABCBC, there are three triples of integers (i,j,k)(i,j,k) that satisfy the conditions: (1,2,3),(1,2,5),(1,4,5)(1,2,3),(1,2,5),(1,4,5). Thus, the ABC number of TT is 33.
You are given a string SS. Each character of SS is A, B, C or ?.
Let QQ be the number of occurrences of ? in SS. We can make 3Q3Q strings by replacing each occurrence of ? in SS with A, B 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+7109+7.
Constraints
- 3≤|S|≤1053≤|S|≤105
- Each character of SS is
A,B,Cor?.
Input
Input is given from Standard Input in the following format:
SS
Output
Print the sum of the ABC numbers of all the 3Q3Q strings, modulo 109+7109+7.
Sample Input 1 Copy
A??C
Sample Output 1 Copy
8
In this case, Q=2Q=2, and we can make 3Q=93Q=9 strings by by replacing each occurrence of ? with A, B or C. The ABC number of each of these strings is as follows:
AAAC: 00AABC: 22AACC: 00ABAC: 11ABBC: 22ABCC: 22ACAC: 00ACBC: 11ACCC: 00
The sum of these is 0+2+0+1+2+2+0+1+0=80+2+0+1+2+2+0+1+0=8, so we print 88 modulo 109+7109+7, that is, 88.
Sample Input 2 Copy
ABCBC
Sample Output 2 Copy
3
When Q=0Q=0, we print the ABC number of SS itself, modulo 109+7109+7. This string is the same as the one given as an example in the problem statement, and its ABC number is 33.
Sample Input 3 Copy
????C?????B??????A???????
Sample Output 3 Copy
979596887
In this case, the sum of the ABC numbers of all the 3Q3Q strings is 22919796129242291979612924, and we should print this number modulo 109+7109+7, that is, 979596887979596887.
动态规划。
#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<algorithm>
#define Max 100005
using namespace std;
typedef long long LL;
const int Mod = ;
char s[Max];
LL dp[][Max];///0 '?' 1 'A' 2 'AB' 3 'ABC'
int a,b;
int main() {
scanf("%s",s + );
dp[][] = ;///初始为1
int n = strlen(s + );
for(int i = ;i <= n;i ++) {
for(int j = ;j <= ;j ++) {
dp[j][i] = dp[j][i - ];///加上之前的
if(s[i] == '?')dp[j][i] = (dp[j][i] * ) % Mod;///如果是问号 有三种选择
if(j && (s[i] == '?' || s[i] - 'A' + == j)) {///如果对应于匹配位置
dp[j][i] = (dp[j][i] + dp[j - ][i - ]) % Mod;
}
}
}
printf("%lld",dp[][n]);
}
AtCoder Beginner Contest 104的更多相关文章
- AtCoder Beginner Contest 100 2018/06/16
A - Happy Birthday! Time limit : 2sec / Memory limit : 1000MB Score: 100 points Problem Statement E8 ...
- AtCoder Beginner Contest 052
没看到Beginner,然后就做啊做,发现A,B太简单了...然后想想做完算了..没想到C卡了一下,然后还是做出来了.D的话瞎想了一下,然后感觉也没问题.假装all kill.2333 AtCoder ...
- AtCoder Beginner Contest 053 ABCD题
A - ABC/ARC Time limit : 2sec / Memory limit : 256MB Score : 100 points Problem Statement Smeke has ...
- AtCoder Beginner Contest 136
AtCoder Beginner Contest 136 题目链接 A - +-x 直接取\(max\)即可. Code #include <bits/stdc++.h> using na ...
- AtCoder Beginner Contest 137 F
AtCoder Beginner Contest 137 F 数论鬼题(虽然不算特别数论) 希望你在浏览这篇题解前已经知道了费马小定理 利用用费马小定理构造函数\(g(x)=(x-i)^{P-1}\) ...
- AtCoder Beginner Contest 076
A - Rating Goal Time limit : 2sec / Memory limit : 256MB Score : 100 points Problem Statement Takaha ...
- AtCoder Beginner Contest 079 D - Wall【Warshall Floyd algorithm】
AtCoder Beginner Contest 079 D - Wall Warshall Floyd 最短路....先枚举 k #include<iostream> #include& ...
- AtCoder Beginner Contest 064 D - Insertion
AtCoder Beginner Contest 064 D - Insertion Problem Statement You are given a string S of length N co ...
- AtCoder Beginner Contest 075 D - Axis-Parallel Rectangle【暴力】
AtCoder Beginner Contest 075 D - Axis-Parallel Rectangle 我要崩溃,当时还以为是需要什么离散化的,原来是暴力,特么五层循环....我自己写怎么都 ...
随机推荐
- Lua学习四----------Lua变量
© 版权声明:本文为博主原创文章,转载请注明出处 1.Lua变量 - 变量在使用前,必须在代码中进行声明,即创建该变量 - 编译程序执行代码之前编译器需要知道如何给语句变量开辟存储区,用于存储变量的值 ...
- spring中的事件 applicationevent 讲的确实不错
event,listener是observer模式一种体现,在spring 3.0.5中,已经可以使用annotation实现event和eventListner里. 我们以spring-webflo ...
- 已知某公司总人数为W,平均年龄为Y岁(每年3月末计算,同时每年3月初入职新人),假设每年离职率为x,x>0&&x<1,每年保持所有员工总数不变进行招聘,新员工平均年龄21岁。 从今年3月末开始,请实现一个算法,可以计算出第N年后公司员工的平均年龄。(最后结果向上取整)。
// ConsoleApplication12.cpp : 定义控制台应用程序的入口点. // #include "stdafx.h" // ConsoleApplication1 ...
- 可能是目前市面上唯一能够支持全平台的RTMP推流组件:Windows、Linux、Android、iOS、ARM
EasyRTMP是什么? EasyRTMP是一套RTMP直播推送功能组件,内部集成了包括:基本RTMP协议.断线重连.异步推送.环形缓冲区.推送网络拥塞自动丢帧.缓冲区关键帧检索.事件回调(断线.音视 ...
- EasyPlayerPro Windows播放器电子放大/局部放大播放功能实现
背景描述 在视频监控软件中,我们看到很多的软件都有电子放大功能, 按住鼠标左键不放,框选一个区域,再松开鼠标左键,即对选中的区域进行放大显示, 且可以重复该操作,逐步放大所需显示的区域, 有没有觉得, ...
- C#单元测试(转)
C#,单元测试入门(以下内容可能来自网络) 一.什么叫单元测试(unit testing)? 是指对软件中的最小可测试单元进行检查和验证.对于单元测试中单元的含义,一般来说,要根据实际情况去判定其具体 ...
- 使用Fiddler测试HTTP接口
Fiddler下载地址:https://www.telerik.com/download/fiddler/fiddler4 在测试http接口前,为避免干扰,我们启用过滤器 然后运行过滤器设置 我们以 ...
- Java图像处理最快技术:ImageJ 学习第一篇
ImageJ是世界上最快的纯Java的图像处理程序. 它能够过滤一个2048x2048的图像在0.1秒内(*). 这是每秒40万像素!ImageJ的扩展通过使用内置的文本编辑器和Java编译器的Ima ...
- keras: 在构建LSTM模型时,使用变长序列的方法
众所周知,LSTM的一大优势就是其能够处理变长序列.而在使用keras搭建模型时,如果直接使用LSTM层作为网络输入的第一层,需要指定输入的大小.如果需要使用变长序列,那么,只需要在LSTM层前加一个 ...
- Android Weekly Notes Issue #322
Android Weekly Issue #322 August 12th, 2018 Android Weekly Issue #322. 本期内容包括: 键盘的图像支持; 网络安全实现; Kotl ...