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. 使用GitHub建立自己的个人主页

    1.建仓库 在自己的库里建一个hujun123qwe.github.io的库 即可以使用这个名字当网址访问. 2.写内容 在库里建一个首页文件 index.html 这个个人主页只支持静态的内容,像p ...

  2. Timer定时器

    try { mTimerGoOut = new Timer(); SimpleDateFormat sdf3 = new SimpleDateFormat("yyyy-MM-dd" ...

  3. angular入门系列教程3

    主题: 本篇主要目的就是继续完善home页,增加tab导航的三个页index index1 index2 效果图: 细节: 初始化的JS就是咱们的home.js,仔细来看. angular的route ...

  4. 数字PID控制算法

    增量式PID控制算法 量式PID控制算法 2009-07-18 10:33 (转载 出处blog.ednchina.com/tengjingshu )blog.ednchina.com/tengjin ...

  5. iOS开发之静态库的制作

    当你需要和别人分享代码,但又不想让别人看到你内部的实现时就需要制作静态库,通常用于第三方SDK 下面就分享一下制作静态库(.a)的过程: 1.打开Xcode,新建workspace 2.随便给work ...

  6. CString 转换成 char *

    最近用到CString类,转换成 char * 类型,下面介绍用法: 一.CString 和 LPSTR 转换: CString转换成LPSTR: 方法一:CString server; LPSTR ...

  7. jquery 实现层级下拉框联动效果 代码

    <select name="fCareId" id="fCareId"> <option selected="selected&qu ...

  8. java给图片加水印代码

    try { String targetImg = "D:/Blue hills.jpg"; // String pressImg = "D:/20130311220300 ...

  9. Mongo常用操作

    设置登陆验证 进入Mongo添加用户    db.addUser('root','123456') 编辑Mongo配置文件  vi /etc/mongod.conf   找到#auth = true ...

  10. python参考手册--第1章python简介

    1.if __name__ == '__main__': 直接运行myModel.py时,当前模块的名字是main:import myModel然后运行的时候当前模块的名字是myModel. 2.ev ...