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更 ...
随机推荐
- 线程相关函数(6)-pthread_cond_wait(),pthread_cond_signal(), 条件变量
pthread_cond_tpthread_cond_initpthread_cond_destroypthread_cond_waitpthread_cond_timedwaitpthread_co ...
- libxml2实例
// libxmlTest.cpp : 定义控制台应用程序的入口点. // #include "stdafx.h" #include <stdio.h> #includ ...
- 2018.7.13vue知识小结
//配置是否允许vue-devtools检查代码,方便调试,生产环境中需要设置为false Vue.config.devtools=false; Vue.config.productionTip=fa ...
- libcpmt.lib (xxx.obj) LNK2038: mismatch detected for 'RuntimeLibrary': value 'MT_StaticRelease' doesn't match value 'MD_DynamicRelease' in XXX.obj
问题描述: 这样的,我写了个NString类,然后用的VS2013的命令行编译的(NMAKE.exe),并用LNK.exe打包成了NString.lib 然后后来我在VS2013里面建了一个proje ...
- mem_fun与mem_fun_ref的区别
一句话:container<ClassType*>就用mem_fun,container<ClassType>就用mem_fun_ref 参考: http://www.cplu ...
- alsamixer + alsactl 控制放音通道
1 使用alsamixer的gui界面配置放音(控制OUT1,OUT2的音量); 2 退出alsamixer,使用alsactl store生成配置文件,文件位于/etc/asound.state; ...
- Flowplayer-一款免费的WEB视频播放器(转)
Flowplayer 是一个开源(GPL 3的)WEB视频播放器.您可以将该播放器嵌入您的网页中,如果您是开发人员,您还可以自由定制和配置播放器相关参数以达到您要的播放效果.本文主要介绍Flowpla ...
- Spring.Net框架三:使用Spring.Net框架实现多数据库
在前面的两篇文章中简单介绍了Spring.Net和如何搭建Spring.Net的环境,在本篇文章中将使用Spring.Net实现多数据库的切换. 一.建立一个空白的解决方案,名称为“SpringDot ...
- IOS 中微信 网页授权报 key[也就是code]失效 解决办法
枪魂微信平台ios手机点击返回 网页授权失败,报key失效.已经解决,原因是授权key只能使用一次,再次使用就会失效. 解决办法:第一次从菜单中进行授权时,用session记录key和open_id. ...
- Try中如果发现错误,即跳出try去匹配catch,那么try后面的语句就不会被执行
例:public void print() throws Exception. 对于方法a,如果它定义了throws Exception.那么当它调用的方法b返回异常对象时,方法a并不处理,而将这个异 ...