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. android.animation(3) - ValueAnimator-ofObject(TypeEvaluator evaluator, Object... values)

    一.ofObject()概述 前面我们讲了ofInt()和ofFloat()来定义动画,但ofInt()只能传入Integer类型的值,而ofFloat()则只能传入Float类型的值.那如果我们需要 ...

  2. 深入浅出MFC--第一章

    Windows程序的生与死 当使用者按下系统菜单中的Close命令项,系统送出WM_CLOSE.通常程序的窗口函数不拦截次消息,于是DefWindowProc函数处理它.DefWindowProc收到 ...

  3. request的生存期只限于服务器跳转

    症状: 刚才想做一个实验,在a.jsp中向request添加属性(页面编码为UTF-8),在b.jsp中删除该属性(页面编码为ISO-8859-1),通过ServletRequestAttribute ...

  4. 纯css3实现的竖形二级导航

    之前为大家分享了好多导航菜单.今天给大家带来一款纯css3实现的竖形二级导航.这款导航菜单可以是无限级.一起看下效果图: 在线预览   源码下载 实现的代码. html代码: <div styl ...

  5. pentestbox使用教程

    pentestbox工具列表:https://tools.pentestbox.org/ freebuf入门实战:http://www.freebuf.com/sectool/125881.html ...

  6. cocos2d-x中CCEditbox导出到lua

    自从工作后感觉时间较少(每天工作9-22,晚上就不想动了,早上想多睡点),工作中用的是 cocos2d-x.cocos2d-x是一款手机游戏引擎,虽然支持lua,但和love2d相比非纯lua游戏引 ...

  7. Excel关闭事件

    记录一下,弄VBA曾经遇到一个需求,遇到用到这个事件,找了很久,最后还是问别人才知道的. Sub Auto_Close() ThisWorkbook.Saved = True End Sub

  8. myeclipse 上安装 Maven3<转>

    环境准备: JDK 1.6 Maven 3.0.4 myeclipse 8.6.1 安装 Maven 之前要求先确定你的 JDK 已经安装配置完成.Maven是 Apache 下的一个项目,目前最新版 ...

  9. Linux系统查看公网IP地址

    curl members.3322.org/dyndns/getip

  10. 如何解决redis高并发客户端频繁time out?

    解决方案:https://www.zhihu.com/question/24781521