Codeforces Round #427 (Div. 2)—A,B,C,D题
A. Key races
题目链接:http://codeforces.com/contest/835/problem/A
题目意思:两个比赛打字,每个人有两个参数v和t,v秒表示他打每个字需要多久时间,等这个这个字传递过去需要t秒,而且在打第一个字之前也会有一个反应时间t。问第一个人可不可以获胜。
题目思路:这个题目当时题目没读懂,明白之后就是一个非常简单的题目了。
(s*v1+2*t1)<(s*v2+2*t2)第一个人就可以获胜
(s*v1+2*t1)==(s*v2+2*t2) 就会平局,否则第二个人获胜。
每个人完成任务的时间为,v*s+2*t,打s个字的需要的时间s*v,开始的时候的反应的时间t,最后一个字打完以后还需要t的时间才结束。
代码:
//Author: xiaowuga
#include <iostream>
#include <algorithm>
#include <set>
#include <vector>
#include <queue>
#include <cmath>
#include <cstring>
#include <cstdio>
#include <ctime>
#include <map>
#include <bitset>
#include <cctype>
#define maxx INT_MAX
#define minn INT_MIN
#define inf 0x3f3f3f3f
#define mem(s,ch) memset(s,ch,sizeof(s))
#define nc cout<<"nc"<<endl
const long long N=;
using namespace std;
typedef long long LL;
int main() {
ios::sync_with_stdio(false);cin.tie();
int s,t1,t2,v1,v2;
cin>>s>>v1>>v2>>t1>>t2;
if((s*v1+*t1)<(s*v2+*t2)) cout<<"First"<<endl;
else if((s*v1+*t1)==(s*v2+*t2)) cout<<"Friendship"<<endl;
else cout<<"Second"<<endl;
return ;
}
B. The number on the board
题目链接:http://codeforces.com/contest/835/problem/B
题目意思:给出一个自然数(这个自然数非常大,肯定爆long long,所以要用字符串读入),如果各位之和小于k,最少改动多少位才能使各位之和不小于k。如果已经大于等于k就输出0。
题目思路:运用贪心的思路。我们即可以把所有字符读进来,排序,然后从最小的字符开始把他们依次变成9,直到总和等于k为止,我们也可以采用分桶法(因为总共就只有9中字符),然后我们从0-9直接替换,就好了,其实也是一种排序的思路。只不过分桶法的复杂度是n,相对于快排的nlogn更加好而已。
代码:
//Author: xiaowuga
#include <iostream>
#include <algorithm>
#include <set>
#include <vector>
#include <queue>
#include <cmath>
#include <cstring>
#include <cstdio>
#include <ctime>
#include <map>
#include <bitset>
#include <cctype>
#define maxx INT_MAX
#define minn INT_MIN
#define inf 0x3f3f3f3f
#define mem(s,ch) memset(s,ch,sizeof(s))
#define nc cout<<"nc"<<endl
const long long N=;
using namespace std;
typedef long long LL;
int main() {
ios::sync_with_stdio(false);cin.tie();
int s,t1,t2,v1,v2;
cin>>s>>v1>>v2>>t1>>t2;
if((s*v1+*t1)<(s*v2+*t2)) cout<<"First"<<endl;
else if((s*v1+*t1)==(s*v2+*t2)) cout<<"Friendship"<<endl;
else cout<<"Second"<<endl;
return ;
}
C. Star sky
题目链接:http://codeforces.com/contest/835/problem/C
题目意思:在一个100*100矩阵里面存在一些星星,每个星星都有自己的坐标和初始亮度,所有的星星都有一个最大亮度。每个星星达到最大亮度亮度以后就会变成0亮度(以此循环),现在给出一个范围,问这个范围内某个时间所有星星的亮度总和。注:边界上的也算范围内的。
题目思路:1 ≤ xi, yi ≤ 100, 0 ≤ si ≤ c ≤ 10,我们观察到题目给出的范围都很小,所以我们使用考虑使用一个三维数组d[x][y][c]表示(0,0),(x,0),(0,y),(x,y)四个点所围成的区域内所有初始亮度为c的数量。这样我们就可以通过容斥定理,得到任意一个范围内所有初始亮度为0-c的数量,根据时间取膜算出t时间亮度乘以数量,加在总和上,输出总和就可以了。好像有树状数组的做法,现在不会,不过这道题用这个方法已经可以AC了。
代码:
//Author: xiaowuga
#include <iostream>
#include <algorithm>
#include <set>
#include <vector>
#include <queue>
#include <cmath>
#include <cstring>
#include <cstdio>
#include <ctime>
#include <map>
#include <bitset>
#include <cctype>
#define maxx INT_MAX
#define minn INT_MIN
#define inf 0x3f3f3f3f
#define mem(s,ch) memset(s,ch,sizeof(s))
#define nc cout<<"nc"<<endl
const long long N=;
using namespace std;
typedef long long LL;
int dp[N][N][]={};
int p[N][N]={};
int w[N][N];
int main() {
ios::sync_with_stdio(false);cin.tie();
LL n,q,c;
cin>>n>>q>>c;
for(int i=;i<n;i++){
int x,y,z;
cin>>x>>y>>z;
dp[x][y][z]++;
}
for(int i=;i<=;i++)
for(int j=;j<=;j++){
for(int k=;k<=;k++){
dp[i][j][k]+=dp[i-][j][k]+dp[i][j-][k]-dp[i-][j-][k];
}
}
LL t,x1,x2,y1,y2;
while(q--){
cin>>t>>x1>>y1>>x2>>y2;
LL tot=;
for(int i=;i<=;i++){
int tmp=dp[x2][y2][i]-dp[x1-][y2][i]-dp[x2][y1-][i]+dp[x1-][y1-][i];
if(i+t<=c) tot+=(i+t)*tmp;
else{
LL x=t-(c-i+);
tot+=(x%(c+))*tmp;
}
}
cout<<tot<<endl; }
return ;
}
D. Palindromic characteristics
题目链接:http://codeforces.com/contest/835/problem/D
题目意思:定义一个k阶回文串,如果一个回文串,由左右连个回文串组成,那么他就是一个2阶回文串,如果其中一边(其中两边是一样的),又可以分解成两个回文串组成的回文串,那么他就是一个3届回文串,那么这个回文串既是1阶回文串,又是2阶回文串,还是一个三阶回文串,问整个字符串有多少个(1-len)阶回文串,输出一行。
思路:可以n^2先预处理一个二维的表来表示,下标i到下标j是否是一个回文串。然后对于每个回文串进行一次递归操作直到他的左右分成的两边不再是回文串,判断他对答案的贡献。
注:一个字符也是一个1阶回文串,所以答案的时候记得把ans[1]+len,回文串递归的时候注意奇数长度的回文串和偶数长度的回文串。分成两边是不同的。
代码:
//Author: xiaowuga
#include <iostream>
#include <algorithm>
#include <set>
#include <vector>
#include <queue>
#include <cmath>
#include <cstring>
#include <cstdio>
#include <ctime>
#include <map>
#include <bitset>
#include <cctype>
#define maxx INT_MAX
#define minn INT_MIN
#define inf 0x3f3f3f3f
#define mem(s,ch) memset(s,ch,sizeof(s))
#define nc cout<<"nc"<<endl
const long long N=+;
using namespace std;
typedef long long LL;
typedef int II;
II pd[N][N]={};
II ans[N]={};
II dfs(II l,II r){
if(r-l<=) return ;
int t=;
int x=r-l+;
II y=(l+r)/;
if(x%){
if(pd[l][y-]&&pd[y+][r]){
t+=dfs(l,y-);
}
}
else{
if(pd[l][y]&&pd[y+][r]){
t+=dfs(l,y);
}
}
if(t!=) ans[t]++;
return t; }
II solve(II l,II r){
int t=;
int x=r-l+;
II y=(l+r)/;
if(x%){
if(pd[l][y-]&&pd[y+][r]){
t+=dfs(l,y-);
}
}
else{
if(pd[l][y]&&pd[y+][r]){
t+=dfs(l,y);
}
}
return t;
}
int main() {
ios::sync_with_stdio(false);cin.tie();
char q[N];
cin>>(q+);
II len=strlen(q+);
for(II i=;i<=len;i++) pd[i][i]=;
for(II i=;i<=len;i++){
for(II j=;(i+j)<=len&&(i-j)>=;j++){
if(q[i+j]==q[i-j]) pd[i-j][i+j]=;
else break;
}
for(II j=;(i-j)>=&&(i+j+)<=len;j++){
if(q[i-j]==q[i+j+]) pd[i-j][i+j+]=;
else break;
}
}
for(II i=;i<=len;i++)
for(II j=i+;j<=len;j++){
if(pd[i][j]){
ans[]++;
int t;
t=solve(i,j);
//cout<<i<<" "<<j<<" "<<t<<endl;
if(t!=) ans[t]++;
}
}
ans[]+=len;
for(II i=;i<=len;i++){
if(i==) cout<<ans[i];
else cout<<" "<<ans[i];
}
cout<<endl;
return ;
}
Codeforces Round #427 (Div. 2)—A,B,C,D题的更多相关文章
- CodeForces 835C - Star sky | Codeforces Round #427 (Div. 2)
s <= c是最骚的,数组在那一维开了10,第八组样例直接爆了- - /* CodeForces 835C - Star sky [ 前缀和,容斥 ] | Codeforces Round #4 ...
- CodeForces 835D - Palindromic characteristics | Codeforces Round #427 (Div. 2)
证明在Tutorial的评论版里 /* CodeForces 835D - Palindromic characteristics [ 分析,DP ] | Codeforces Round #427 ...
- Codeforces Round #367 (Div. 2) A. Beru-taxi (水题)
Beru-taxi 题目链接: http://codeforces.com/contest/706/problem/A Description Vasiliy lives at point (a, b ...
- Codeforces Round #575 (Div. 3) 昨天的div3 补题
Codeforces Round #575 (Div. 3) 这个div3打的太差了,心态都崩了. B. Odd Sum Segments B 题我就想了很久,这个题目我是找的奇数的个数,因为奇数想分 ...
- Codeforces Round #334 (Div. 2) A. Uncowed Forces 水题
A. Uncowed Forces Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/604/pro ...
- Codeforces Round #427 (Div. 2) Problem D Palindromic characteristics (Codeforces 835D) - 记忆化搜索
Palindromic characteristics of string s with length |s| is a sequence of |s| integers, where k-th nu ...
- Codeforces Round #427 (Div. 2) Problem C Star sky (Codeforces 835C) - 前缀和
The Cartesian coordinate system is set in the sky. There you can see n stars, the i-th has coordinat ...
- Codeforces Round #427 (Div. 2) Problem A Key races (Codeforces 835 A)
Two boys decided to compete in text typing on the site "Key races". During the competition ...
- Codeforces Round #427 (Div. 2) B. The number on the board
引子: A题过于简单导致不敢提交,拖拖拉拉10多分钟还是决定交,太冲动交错了CE一发,我就知道又要错过一次涨分的机会.... B题还是过了,根据题意目测数组大小开1e5,居然蒙对,感觉用vector更 ...
随机推荐
- 根据返回值动态加载select
// 路由 if (return_routeChoice != null && return_routeChoice != "") { for (var i = 0 ...
- JS中声明全局变量
JS中声明全局变量主要分为显式声明或者隐式声明下面分别介绍. 声明方式一: 使用var(关键字)+变量名(标识符)的方式在function外部声明,即为全局变量,否则在function声明的是局部变量 ...
- JS学习笔记(2)--正则表达式获取指定字符串
js 正则提取字串 这里就有:SA 怎么用正则提取sa出来 var str=“这里就有:SA ”怎么用正则提取sa出来 YDhcui | 浏览 2087 次 推荐于2016-05-30 18:25:4 ...
- 深入学习HttpClient(一)扩展额外的功能
HttpClient作为.net4.5新增的Http库除了对于async/await形式的异步支持外,还向我们展示了其强大的扩展能力. [类库的设计] 让我们先看下Httpclient的设计图: 图中 ...
- Spring的AOP简单理解
最近在研究spring的AOP,翻译出来的意思是面向切面. 总结如下: 所谓AOP就是将分散在各个方法处的公共代码提取到一处, 并通过类似拦截器的机制实现代码的动态整合.可以简单地想象成, 在某个方法 ...
- ar命令学习
之前,学习Linux下使用静态库的时候涉及到了这三个命令: gcc -c my_strcpy.c my_strcmp.car rcs libmylib.a *.ogcc -o main main.c ...
- No output operations registered, so nothing to execute
SparkStreaming和KafKa结合报错!报错之前代码如下: object KafkaWordCount{ val updateFunc = (iter:Iterator[(String,Se ...
- ansible ansible_os_family == "RedHat" and ansible_lsb.major_release|int >= 6 转为数字比大小
字符串转换为数字型再去比较 tasks: - shell: echo "only on Red Hat 6, derivatives, and later" when: ansib ...
- 关于Unity中的.meta文件
.meta文件是用于辅助管理Unity资源文件的文件,删除后,Unity会自动生成,里面记录了各个资源Inspector的信息,属性等等,Unity是不会改变源资源文件的,没有意义,它是靠.meta文 ...
- 5.3 SpEL语法
SqEL是一个可以独立于spring的表达式语言,即它可以用在XML中对语法进行简化 5.3 SpEL语法5.3.1 基本表达式一.字面量表达式: SpEL支持的字面量包括:字符串.数字类型(int. ...