A. Keyboard

题意:一个人打字,可能会左偏一位,可能会右偏一位,给出一串字符,求它本来的串

和紫书的破损的键盘一样

  1. #include<iostream>
  2. #include<cstdio>
  3. #include<cstring>
  4. #include <cmath>
  5. #include<algorithm>
  6. using namespace std;
  7.  
  8. typedef long long LL;
  9. char s[]="qwertyuiopasdfghjkl;zxcvbnm,./";
  10. char a[],t[];
  11.  
  12. int main()
  13. {
  14. char ch;
  15. int i,j,len;
  16. a['L']=;
  17. a['R']=-;
  18. cin>>ch;
  19. cin>>t;
  20. len=strlen(t);
  21. for(i=;i<len;i++){
  22. for(j=;j<;j++){
  23. if(t[i]==s[j]){
  24. t[i]=s[j+a[ch]];
  25. break;
  26. }
  27. }
  28. }
  29. cout<<t<<"\n";
  30. return ;
  31. }

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查找

  1. #include<iostream>
  2. #include<cstdio>
  3. #include<cstring>
  4. #include <cmath>
  5. #include<algorithm>
  6. using namespace std;
  7.  
  8. typedef long long LL;
  9. int a[],b[];
  10.  
  11. int main()
  12. {
  13. int n,m,i,j,x,tmp;
  14. scanf("%d",&n);
  15. for(i=;i<=n;i++) scanf("%d",&a[i]);
  16. b[]=;
  17. b[]=b[]+a[]-;
  18.  
  19. for(i=;i<=n;i++){
  20. b[*i-]=b[*i-]+;
  21. b[*i]=b[*i-]+a[i]-;
  22. }
  23.  
  24. scanf("%d",&m);
  25. while(m--){
  26. scanf("%d",&x);
  27. tmp=lower_bound(b+,b++*n,x)-b;
  28. printf("%d\n",(tmp+)/);
  29. }
  30. return ;
  31. }

后来搜CD的题解时,发现有这样做的,将每一个属于哪一堆储存在数组中 感觉有点类似哈希= =

  1. #include<iostream>
  2. #include<cstdio>
  3. #include<cstring>
  4. #include <cmath>
  5. #include<algorithm>
  6. using namespace std;
  7.  
  8. typedef long long LL;
  9. int vis[];
  10.  
  11. int main()
  12. {
  13. int n,m,i,j,a,s=;
  14. scanf("%d",&n);
  15. for(i=;i<=n;i++){
  16. scanf("%d",&a);
  17. for(j=;j<a;j++){
  18. s++;
  19. vis[s]=i;
  20. }
  21. }
  22.  
  23. scanf("%d",&m);
  24. while(m--){
  25. scanf("%d",&a);
  26.  
  27. printf("%d\n",vis[a]);
  28. }
  29. return ;
  30. }

C. Captain Marmot

题意:给出n个兵团,每个兵团里面有四个点,给出这四个点的起始坐标,旋转中心坐标,问这四个点至少经过多少次旋转能够得到一个正方形

因为一个点只有4种情况,不旋转,旋转90,旋转180,旋转270,

用p[i][j]表示:i表示点的状态,j表示的是这是第几个点。

再4*4*4*4枚举,枚举的时候枚举正方形的边长是否相等,还有对角线长度平方是否为边长平方的2倍

  1. #include<iostream>
  2. #include<cstdio>
  3. #include<cstring>
  4. #include <cmath>
  5. #include<algorithm>
  6. using namespace std;
  7.  
  8. typedef long long LL;
  9. LL d[];
  10.  
  11. struct node{
  12. int x,y;
  13. } p[][],center[];
  14.  
  15. LL dis(node a,node b){
  16. return(LL)(a.x-b.x)*(a.x-b.x)+(a.y-b.y)*(a.y-b.y);
  17. }
  18.  
  19. void check(){
  20. int ans=;
  21. for(int i=;i<;i++)
  22. {
  23. for(int j=;j<;j++)
  24. {
  25. for(int k=;k<;k++)
  26. {
  27. for(int l=;l<;l++)
  28. {
  29. d[]=dis(p[i][],p[j][]);
  30. d[]=dis(p[j][],p[k][]);
  31. d[]=dis(p[k][],p[l][]);
  32. d[]=dis(p[l][],p[i][]);//正方形的4条直角边
  33. d[]=dis(p[i][],p[k][]);// 正方形的对角线
  34. d[]=dis(p[j][],p[l][]);
  35. sort(d,d+);
  36. if(d[]==)
  37. continue;
  38. else
  39. if(d[]==d[]&&d[]==d[]&&d[]==d[]&&d[]*==d[]&&d[]==d[])//判断边长和对角线
  40. {
  41. ans=min(ans,i+j+k+l);
  42.  
  43. }
  44. }
  45.  
  46. }
  47. }
  48. }
  49.  
  50. if(ans!=) printf("%d\n",ans);
  51. else printf("-1\n");
  52. }
  53.  
  54. int main()
  55. {
  56. int n,j;
  57. scanf("%d",&n);
  58. while(n--){
  59. for(int i=;i<;i++)
  60. {
  61. cin>>p[][i].x>>p[][i].y;
  62. cin>>center[i].x>>center[i].y;
  63. int xx=p[][i].x-center[i].x;
  64. int yy=p[][i].y-center[i].y;
  65. p[][i].x=center[i].x-yy;//分别计算出一个点旋转所能够得到的四种状态
  66. p[][i].y=center[i].y+xx;
  67. p[][i].x=center[i].x-xx;
  68. p[][i].y=center[i].y-yy;
  69. p[][i].x=center[i].x+yy;
  70. p[][i].y=center[i].y-xx;
  71. }
  72. check();
  73. }
  74. return ;
  75. }

D. Flowers

题意:给出吃白花必须是k的整数倍,给出吃花朵数的区间 a,b,问满足这样条件的方案数共有多少

dp[i]表示吃到第i朵花的方案数

dp[i]=dp[i-1]+dp[i-k];

  1. #include<iostream>
  2. #include<cstdio>
  3. #include<cstring>
  4. #include <cmath>
  5. #include<algorithm>
  6. using namespace std;
  7.  
  8. typedef long long LL;
  9. int mod=1e9+;
  10. int dp[];
  11.  
  12. int main()
  13. {
  14. int i,j,t,k,a,b;
  15. scanf("%d %d",&t,&k);
  16. dp[]=;
  17. for(i=;i<=;i++){
  18. dp[i]=dp[i-];
  19. if(i>=k) dp[i]=(dp[i]+dp[i-k])%mod;
  20. }
  21.  
  22. for(i=;i<=;i++){
  23. dp[i]=(dp[i]+dp[i-])%mod;//再求出前缀和
  24. }
  25.  
  26. while(t--){
  27. scanf("%d %d",&a,&b);
  28. printf("%d\n",((dp[b]-dp[a-])%mod+mod)%mod);//注意这儿要在括号里面加个mod再mod一次,因为这个挂在了第三个
  29. }
  30. return ;
  31. }

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. 简单制作mib表

    今天放假后第一天上班,将假前自学制作mib表的东西说一下. 在这里呢,我以世界-中国-上海-闵行这种包含关系介绍,感觉更容易理解. MIB file的开始和结束 所有的MIB file的都以DEFIN ...

  2. 存储过程——在LINQ中使用(六)

    上述几篇都将了存储与数据库,关联的一些实例,首先感谢各位大神们在前几篇文章中提到的问题,本人还在学习中,这次介绍下在linq中如何应用存储过程: LINQ简介 语言集成查询(LINQ)在对象领域和数据 ...

  3. C++拷贝构造函数详解(转载)

    一. 什么是拷贝构造函数 首先对于普通类型的对象来说,它们之间的复制是很简单的,例如: int a = 100; int b = a; 而类对象与普通对象不同,类对象内部结构一般较为复杂,存在各种成员 ...

  4. java 回传参数

    通过 new 创建的对象可以实现回传,如数组:自定义类对象里的参数. [数组方式] public static void main(String[] args) { try { int [] amou ...

  5. JSP访问Spring中的bean

    JSP访问Spring中的bean <%@page import="com.sai.comment.po.TSdComment"%> <%@page import ...

  6. 01-03-02-1【Nhibernate (版本3.3.1.4000) 出入江湖】CRUP操作--cascade 级联相关

    要点: 1. <!--双向关联时要用: inverse:由子表来维护关系,cascade:级联的关系 如果没有这个设置, 插入Customer成功(即使现在Order插入Order抛异常,这时产 ...

  7. jQuery中的&& ||

    jQuery1.2.6 clean方法中有这么一段第一眼看去会让人晕掉的方法.完全不知其所言. “||, && 可以这样用?”,“这段东西最终返回的是个什么对象啊?” // Trim ...

  8. VisionTimer BUG && Start

    void Start() { vp_Timer.In(0.0f, delegate() { Debug.Log("Start"); }, 10, 1.0f); } Version ...

  9. CentOS(RHEL) 操作备忘

    1.安装中文语言包及切换 yum groupinstall chinese-support vi /etc/sysconfig/i18n change en_US to zh_CN 2.用户自动登录 ...

  10. Bad configuration option localCommand

     command-line: line 0: Bad configuration option: PermitLocalCommand 2011-12-08 14:04:54 标签:Bad confi ...