Codeforces Round #271 (Div. 2)
A. Keyboard
题意:一个人打字,可能会左偏一位,可能会右偏一位,给出一串字符,求它本来的串
和紫书的破损的键盘一样
#include<iostream>
#include<cstdio>
#include<cstring>
#include <cmath>
#include<algorithm>
using namespace std; typedef long long LL;
char s[]="qwertyuiopasdfghjkl;zxcvbnm,./";
char a[],t[]; int main()
{
char ch;
int i,j,len;
a['L']=;
a['R']=-;
cin>>ch;
cin>>t;
len=strlen(t);
for(i=;i<len;i++){
for(j=;j<;j++){
if(t[i]==s[j]){
t[i]=s[j+a[ch]];
break;
}
}
}
cout<<t<<"\n";
return ;
}
B. Worms
题意:给出n,a[1],a[2],a[3]---a[n],第一堆的编号为1到a[i],第二堆的编号为a[1]+1到a[1]+1+a[2],再给出m个数,询问它们分别在哪一堆
把每一堆的起始和结束储存在b[]数组中,再用lower_bound查找
#include<iostream>
#include<cstdio>
#include<cstring>
#include <cmath>
#include<algorithm>
using namespace std; typedef long long LL;
int a[],b[]; int main()
{
int n,m,i,j,x,tmp;
scanf("%d",&n);
for(i=;i<=n;i++) scanf("%d",&a[i]);
b[]=;
b[]=b[]+a[]-; for(i=;i<=n;i++){
b[*i-]=b[*i-]+;
b[*i]=b[*i-]+a[i]-;
} scanf("%d",&m);
while(m--){
scanf("%d",&x);
tmp=lower_bound(b+,b++*n,x)-b;
printf("%d\n",(tmp+)/);
}
return ;
}
后来搜CD的题解时,发现有这样做的,将每一个属于哪一堆储存在数组中 感觉有点类似哈希= =
#include<iostream>
#include<cstdio>
#include<cstring>
#include <cmath>
#include<algorithm>
using namespace std; typedef long long LL;
int vis[]; int main()
{
int n,m,i,j,a,s=;
scanf("%d",&n);
for(i=;i<=n;i++){
scanf("%d",&a);
for(j=;j<a;j++){
s++;
vis[s]=i;
}
} scanf("%d",&m);
while(m--){
scanf("%d",&a); printf("%d\n",vis[a]);
}
return ;
}
C. Captain Marmot
题意:给出n个兵团,每个兵团里面有四个点,给出这四个点的起始坐标,旋转中心坐标,问这四个点至少经过多少次旋转能够得到一个正方形
因为一个点只有4种情况,不旋转,旋转90,旋转180,旋转270,
用p[i][j]表示:i表示点的状态,j表示的是这是第几个点。
再4*4*4*4枚举,枚举的时候枚举正方形的边长是否相等,还有对角线长度平方是否为边长平方的2倍
#include<iostream>
#include<cstdio>
#include<cstring>
#include <cmath>
#include<algorithm>
using namespace std; typedef long long LL;
LL d[]; struct node{
int x,y;
} p[][],center[]; LL dis(node a,node b){
return(LL)(a.x-b.x)*(a.x-b.x)+(a.y-b.y)*(a.y-b.y);
} void check(){
int ans=;
for(int i=;i<;i++)
{
for(int j=;j<;j++)
{
for(int k=;k<;k++)
{
for(int l=;l<;l++)
{
d[]=dis(p[i][],p[j][]);
d[]=dis(p[j][],p[k][]);
d[]=dis(p[k][],p[l][]);
d[]=dis(p[l][],p[i][]);//正方形的4条直角边
d[]=dis(p[i][],p[k][]);// 正方形的对角线
d[]=dis(p[j][],p[l][]);
sort(d,d+);
if(d[]==)
continue;
else
if(d[]==d[]&&d[]==d[]&&d[]==d[]&&d[]*==d[]&&d[]==d[])//判断边长和对角线
{
ans=min(ans,i+j+k+l); }
} }
}
} if(ans!=) printf("%d\n",ans);
else printf("-1\n");
} int main()
{
int n,j;
scanf("%d",&n);
while(n--){
for(int i=;i<;i++)
{
cin>>p[][i].x>>p[][i].y;
cin>>center[i].x>>center[i].y;
int xx=p[][i].x-center[i].x;
int yy=p[][i].y-center[i].y;
p[][i].x=center[i].x-yy;//分别计算出一个点旋转所能够得到的四种状态
p[][i].y=center[i].y+xx;
p[][i].x=center[i].x-xx;
p[][i].y=center[i].y-yy;
p[][i].x=center[i].x+yy;
p[][i].y=center[i].y-xx;
}
check();
}
return ;
}
D. Flowers
题意:给出吃白花必须是k的整数倍,给出吃花朵数的区间 a,b,问满足这样条件的方案数共有多少
dp[i]表示吃到第i朵花的方案数
dp[i]=dp[i-1]+dp[i-k];
#include<iostream>
#include<cstdio>
#include<cstring>
#include <cmath>
#include<algorithm>
using namespace std; typedef long long LL;
int mod=1e9+;
int dp[]; int main()
{
int i,j,t,k,a,b;
scanf("%d %d",&t,&k);
dp[]=;
for(i=;i<=;i++){
dp[i]=dp[i-];
if(i>=k) dp[i]=(dp[i]+dp[i-k])%mod;
} for(i=;i<=;i++){
dp[i]=(dp[i]+dp[i-])%mod;//再求出前缀和
} while(t--){
scanf("%d %d",&a,&b);
printf("%d\n",((dp[b]-dp[a-])%mod+mod)%mod);//注意这儿要在括号里面加个mod再mod一次,因为这个挂在了第三个
}
return ;
}
Codeforces Round #271 (Div. 2)的更多相关文章
- Codeforces Round #271 (Div. 2)题解【ABCDEF】
Codeforces Round #271 (Div. 2) A - Keyboard 题意 给你一个字符串,问你这个字符串在键盘的位置往左边挪一位,或者往右边挪一位字符,这个字符串是什么样子 题解 ...
- Codeforces Round #271 (Div. 2) F. Ant colony (RMQ or 线段树)
题目链接:http://codeforces.com/contest/474/problem/F 题意简而言之就是问你区间l到r之间有多少个数能整除区间内除了这个数的其他的数,然后区间长度减去数的个数 ...
- Codeforces Round #271 (Div. 2) D. Flowers (递推)
题目链接:http://codeforces.com/problemset/problem/474/D 用RW组成字符串,要求w的个数要k个连续出现,R任意,问字符串长度为[a, b]时,字符串的种类 ...
- Codeforces Round #271 (Div. 2) E题 Pillars(线段树维护DP)
题目地址:http://codeforces.com/contest/474/problem/E 第一次遇到这样的用线段树来维护DP的题目.ASC中也遇到过,当时也非常自然的想到了线段树维护DP,可是 ...
- Codeforces Round #271 (Div. 2) F题 Ant colony(线段树)
题目地址:http://codeforces.com/contest/474/problem/F 由题意可知,最后能够留下来的一定是区间最小gcd. 那就转化成了该区间内与区间最小gcd数相等的个数. ...
- Codeforces Round #271 (Div. 2)-B. Worms
http://codeforces.com/problemset/problem/474/B B. Worms time limit per test 1 second memory limit pe ...
- Codeforces Round #271 (Div. 2)-A. Keyboard
http://codeforces.com/problemset/problem/474/A A. Keyboard time limit per test 2 seconds memory limi ...
- Codeforces Round #271 (Div. 2) 解题报告
题目地址:http://codeforces.com/contest/474 A题:Keyboard 模拟水题. 代码例如以下: #include <iostream> #include ...
- Codeforces Round #271 (Div. 2) F ,E, D, C, B, A
前言:最近被线段树+简单递推DP虐的体无完肤!真是弱! A:简单题,照着模拟就可以,题目还特意说不用处理边界 B:二分查找即可,用lower_lound()函数很好用 #include<stri ...
随机推荐
- 不同的source control下配置DiffMerge
TFS: 1. 打开Option -> Source Control -> Visual Studio TFS -> Configure User Tools; 2. 添加 .*, ...
- BAT CMD 批处理文件脚本 -1
http://www.cnblogs.com/linglizeng/archive/2010/01/29/Bat-CMD-ChineseVerion.html 1. 综述 ...
- 2437: [Noi2011]兔兔与蛋蛋 - BZOJ
Description Input 输入的第一行包含两个正整数 n.m.接下来 n行描述初始棋盘.其中第i 行包含 m个字符,每个字符都是大写英文字母"X".大写英文字母" ...
- 【转】Tarjan&LCA题集
转自:http://blog.csdn.net/shahdza/article/details/7779356 [HDU][强连通]:1269 迷宫城堡 判断是否是一个强连通★2767Proving ...
- Matlab中unifrnd函数使用解析
1.生成N阶[a,b]均匀分布数组 >> unifrnd(3,5,5,5) ans = 3.8651 4.6677 4.8115 4.3456 4.8560 4.0241 3.4079 3 ...
- MongoDB { code: 18, ok: 0.0, errmsg: "auth fails" } 原因
MongoDB出现 { code: 18, ok: 0.0, errmsg: "auth fails" } 错误的原因: 1.账号密码错误 2.账号不属于该数据库
- Codeforces Round #362 (Div. 2)->A. Pineapple Incident
A. Pineapple Incident time limit per test 1 second memory limit per test 256 megabytes input standar ...
- android.os.DeadObjectException memory near r0: 异常处理 Consumer closed input channel or an error occurred. events=0x9
原地址:http://www.cnblogs.com/wanqieddy/p/3495338.html android.os.DeadObjectException memory near r0: 异 ...
- timeit统计运行时间
import timeitt1 = timeit.timeit('sum(x*x for x in xrange(10000))',number = 10000) print t1
- Javascript 选项卡
<!DOCTYPE html> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <m ...