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

  1. Codeforces Round #271 (Div. 2)题解【ABCDEF】

    Codeforces Round #271 (Div. 2) A - Keyboard 题意 给你一个字符串,问你这个字符串在键盘的位置往左边挪一位,或者往右边挪一位字符,这个字符串是什么样子 题解 ...

  2. Codeforces Round #271 (Div. 2) F. Ant colony (RMQ or 线段树)

    题目链接:http://codeforces.com/contest/474/problem/F 题意简而言之就是问你区间l到r之间有多少个数能整除区间内除了这个数的其他的数,然后区间长度减去数的个数 ...

  3. Codeforces Round #271 (Div. 2) D. Flowers (递推)

    题目链接:http://codeforces.com/problemset/problem/474/D 用RW组成字符串,要求w的个数要k个连续出现,R任意,问字符串长度为[a, b]时,字符串的种类 ...

  4. Codeforces Round #271 (Div. 2) E题 Pillars(线段树维护DP)

    题目地址:http://codeforces.com/contest/474/problem/E 第一次遇到这样的用线段树来维护DP的题目.ASC中也遇到过,当时也非常自然的想到了线段树维护DP,可是 ...

  5. Codeforces Round #271 (Div. 2) F题 Ant colony(线段树)

    题目地址:http://codeforces.com/contest/474/problem/F 由题意可知,最后能够留下来的一定是区间最小gcd. 那就转化成了该区间内与区间最小gcd数相等的个数. ...

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

  7. Codeforces Round #271 (Div. 2)-A. Keyboard

    http://codeforces.com/problemset/problem/474/A A. Keyboard time limit per test 2 seconds memory limi ...

  8. Codeforces Round #271 (Div. 2) 解题报告

    题目地址:http://codeforces.com/contest/474 A题:Keyboard 模拟水题. 代码例如以下: #include <iostream> #include ...

  9. Codeforces Round #271 (Div. 2) F ,E, D, C, B, A

    前言:最近被线段树+简单递推DP虐的体无完肤!真是弱! A:简单题,照着模拟就可以,题目还特意说不用处理边界 B:二分查找即可,用lower_lound()函数很好用 #include<stri ...

随机推荐

  1. adb shell 出现 error :

    首先,确保 adb 服务有起来    adb kill-server adb start-server其次,确保 adb devices 可以找到设备

  2. android studio 不能在线更新android SDK Manager问题解决办法

    Failed to fetch URL https://dl-ssl.google.com/android/repository/addons_list-2.xml, reason: Connecti ...

  3. HDU 4811 Ball 贪心

    题目链接: 题目 Ball Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) 问题描述 ...

  4. C#根据日期DateTime和持续时间int找到日期

    protected DateTime GetFinish(DateTime start, int duration) { return start.AddDays(duration); } prote ...

  5. [转载]GDI+中发生一般性错误

    注:第一次写博客,把自己遇到的问题和收集的资料记录在博客上.在开发.NET应用中,使用 System.Drawing.Image.Save 方法而导致“GDI+ 中发生一般性错误”的发生,通常有以下三 ...

  6. linux系统进程的内存布局

    内存管理模块是操作系统的心脏:它对应用程序和系统管理非常重要.今后的几篇文章中,我将着眼于实际的内存问题,但也不避讳其中的技术内幕.由于不少概念是通用的,所以文中大部分例子取自32位x86平台的Lin ...

  7. linux cmake 安装mysql5.5.11,以及更高版本

    1.下载mysql5.5.12和cmake wget http://mirrors.sohu.com/mysql/MySQL-5.5/mysql-5.5.12-linux2.6-i686.tar.gz ...

  8. node-firefox 二三事

    编者按:本文作者为 Soledad Penadés, Sole 在 Mozilla 的 Tech Evangelism 团队工作,帮助人们在网络上创造神奇的东西.本文主要介绍node-firefox的 ...

  9. 全球说:要给 OneAlert 点100个赞

    客户背景 「全球说」 Talkmate,是北京酷语时代教育科技有限公司(酷语科技)旗下产品,酷语科技是一家诞生于中国的语言技术公司,致力于为全球用户提供一个全新的多语言学习和社交网络平台 . 全球说是 ...

  10. POJ 1270 Following Orders (拓扑排序,dfs枚举)

    题意:每组数据给出两行,第一行给出变量,第二行给出约束关系,每个约束包含两个变量x,y,表示x<y.    要求:当x<y时,x排在y前面.让你输出所有满足该约束的有序集. 思路:用拓扑排 ...