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题的更多相关文章

  1. CodeForces 835C - Star sky | Codeforces Round #427 (Div. 2)

    s <= c是最骚的,数组在那一维开了10,第八组样例直接爆了- - /* CodeForces 835C - Star sky [ 前缀和,容斥 ] | Codeforces Round #4 ...

  2. CodeForces 835D - Palindromic characteristics | Codeforces Round #427 (Div. 2)

    证明在Tutorial的评论版里 /* CodeForces 835D - Palindromic characteristics [ 分析,DP ] | Codeforces Round #427 ...

  3. Codeforces Round #367 (Div. 2) A. Beru-taxi (水题)

    Beru-taxi 题目链接: http://codeforces.com/contest/706/problem/A Description Vasiliy lives at point (a, b ...

  4. Codeforces Round #575 (Div. 3) 昨天的div3 补题

    Codeforces Round #575 (Div. 3) 这个div3打的太差了,心态都崩了. B. Odd Sum Segments B 题我就想了很久,这个题目我是找的奇数的个数,因为奇数想分 ...

  5. 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 ...

  6. 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 ...

  7. 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 ...

  8. 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 ...

  9. Codeforces Round #427 (Div. 2) B. The number on the board

    引子: A题过于简单导致不敢提交,拖拖拉拉10多分钟还是决定交,太冲动交错了CE一发,我就知道又要错过一次涨分的机会.... B题还是过了,根据题意目测数组大小开1e5,居然蒙对,感觉用vector更 ...

随机推荐

  1. iconv 解决乱码问题

    [root@NGINX-APACHE-SVN pro]# file 林.txt 林.txt: ISO-8859 text, with no line terminators #在LINUX下显示乱码 ...

  2. 源码分析:Java堆的创建

    虚拟机在内存中申请一片区域,由虚拟机自动管理,用来满足应用程序对象分配的空间需求,即堆空间. 由于程序运行的局部特性,程序创建的大多数对象都具有非常短的生命周期,而程序也会创建一些生命周期特别长的对象 ...

  3. 【转】搞清楚LzoCodec和LzopCodec

    使用LZO过程会发现它有两种压缩编码可以使用,即LzoCodec和LzopCodec,下面说说它们区别: LzoCodec比LzopCodec更快, LzopCodec为了兼容LZOP程序添加了如 b ...

  4. 拿与不拿的dfs

    在n个物品中拿k个,使得花费恰好为m. 典型的dfs,对每一个物品,可以选择拿与不拿,然后在判断下一个物品. 失败的dfs: 代码没有保存,只重写一下dfs函数的关键部分: ;i<n;i++) ...

  5. 2017年网站安全狗绕过WebShell上传拦截的新姿势

    本文来源:https://www.webshell.ren/post-308.html 今天有一位朋友发一个上传点给我 我一看是南方cms 有双文件上传漏洞 本来可以秒的 但是看到了 安全狗 从图片可 ...

  6. 第二百七十四节,同源策略和跨域Ajax

    同源策略和跨域Ajax 什么是同源策略  尽管浏览器的安全措施多种多样,但是要想黑掉一个Web应用,只要在浏览器的多种安全措施中找到某种措施的一个漏洞或者绕过一种安全措施的方法即可.浏览器的各种保安措 ...

  7. EMPTY表示元素不能包含文本,也不能包含子元素

    <?xml version=”1.0″ encoding=”GB2312″?> <!ELEMENT Customer EMPTY> <!ATTLIST Customer称 ...

  8. C#三种模拟自动登录和提交POST信息的实现方法【转】

    网页自动登录(提交Post内容)的用途很多,如验证身份.程序升级.网络投票等,以下是用C#实现的方法.       网页自动登录和提交POST信息的核心就是分析网页的源代码(HTML),在C#中,可以 ...

  9. 小结:hash

    概要: 判重的时候可以用手写hash,也可以用stl中的map,手写hash的好处是快,解决冲突的方案较好,map慢.但是手写hash要求的空间高,而且有时处理得不好的话会wa. 注意及技巧: 注意的 ...

  10. nginx php文件上传的大小配置问题