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更 ...
随机推荐
- 【剑指Offer学习】【面试题22:栈的压入、弹出序列】
题目:输入两个整数序列,第一个序列表示栈的压入顺序,请推断二个序列是否为该栈的弹出顺序.假设压入栈的全部数字均不相等. 解题思路: 解决问题非常直观的想法就是建立一个辅助栈.把输入的第一个序列中的数字 ...
- 搜索引擎根据原Sphider的脚本修正后的 Sphider-plus 2.2
搜索引擎根据原Sphider的脚本修正后的 Sphider-plus 2.2 标签: 搜索引擎脚本search数据库authorizationjavascript -- : 1412人阅读 评论() ...
- mem_fun与mem_fun_ref的区别
一句话:container<ClassType*>就用mem_fun,container<ClassType>就用mem_fun_ref 参考: http://www.cplu ...
- web.config中的connectionString里面应该怎么写?
2009-09-16 10:19信欣玛利 | 浏览 6068 次 网络 就是具体格式.. 谁能举个例子? asp.net 3.5的. 2009-09-16 10:40 提问者采纳 这是用来连 ...
- ngx_lua 随笔
--[[ test --]] ngx.header.content_type = "text/plain"; --输出头部 local user = ngx.var.arg_use ...
- js学习笔记26----事件冒泡,事件捕获
事件冒泡 : 当一个元素接收到事件的时候,会把它接收到的所有传播给它的父级.一直到顶层window.这种现象称之为事件冒泡机制.出去的事件触发. 阻止冒泡 : 当前要阻止冒泡的事件函数中,调用 eve ...
- VSS (Visual Source Safe 2005) 用法详解
VSS用法指南 The usage of VSS (Visual Source Safe 2005) 1. 首先,当然是得安装好Visual Source Safe 2005 你可以在Visual S ...
- Reveal Jquery 模式对话框插件
/* * jQuery Reveal Plugin 1.0 * www.ZURB.com * Copyright 2010, ZURB * Free to use under the MIT lice ...
- javascript jquery数组操作小结
----------------------------------------------------------定义数组-------------------------------------- ...
- git error Another git process seems to be running in this repository
How to fix error Another git process seems to be running in this repository When you use Git, you se ...