Codeforces 474(#270) 解题报告

A:直接贴过来装换

解题代码

 1 // File Name: a.cpp
 2 // Author: darkdream
 3 // Created Time: 2014年10月06日 星期一 23时28分57秒
 4
 5 #include<vector>
 6 #include<list>
 7 #include<map>
 8 #include<set>
 9 #include<deque>
10 #include<stack>
11 #include<bitset>
12 #include<algorithm>
13 #include<functional>
14 #include<numeric>
15 #include<utility>
16 #include<sstream>
17 #include<iostream>
18 #include<iomanip>
19 #include<cstdio>
20 #include<cmath>
21 #include<cstdlib>
22 #include<cstring>
23 #include<ctime>
24 #define LL long long
25
26 using namespace std;
27 char  str[102];
28 char  tp[4][100] = {"qwertyuiop",
29 "asdfghjkl;",
30 "zxcvbnm,./",
31 };
32 int main(){
33     scanf("%s",str);
34     if(str[0] == ‘L‘)
35     {
36        scanf("%s",str);
37        for(int i = 0;i < strlen(str);i ++)
38        {
39             for(int j = 0;j <= 2;j ++)
40             {
41                if(strchr(tp[j],str[i]))
42                {
43                  printf("%c",tp[j][strchr(tp[j],str[i]) - tp[j] +1]);
44                }
45             }
46        }
47     }
48   else{
49        scanf("%s",str);
50        for(int i = 0;i < strlen(str);i ++)
51        {
52             for(int j = 0;j <= 2;j ++)
53             {
54                if(strchr(tp[j],str[i]))
55                {
56                  printf("%c",tp[j][strchr(tp[j],str[i]) - tp[j] - 1]);
57                }
58             }
59
60        }
61   }
62 return 0;
63 }

B:一个标记或者二分就行,最大1e6的复杂度

解题代码:

 1 // File Name: b.cpp
 2 // Author: darkdream
 3 // Created Time: 2014年10月06日 星期一 23时39分31秒
 4
 5 #include<vector>
 6 #include<list>
 7 #include<map>
 8 #include<set>
 9 #include<deque>
10 #include<stack>
11 #include<bitset>
12 #include<algorithm>
13 #include<functional>
14 #include<numeric>
15 #include<utility>
16 #include<sstream>
17 #include<iostream>
18 #include<iomanip>
19 #include<cstdio>
20 #include<cmath>
21 #include<cstdlib>
22 #include<cstring>
23 #include<ctime>
24 #define LL long long
25
26 using namespace std;
27 int a[100005];
28 int b[100005];
29 int n , m ;
30 int find(int x)
31 {
32     int l = 1;
33     int r = n;
34     while(l <= r)
35     {
36       int mid = (l + r)/2;
37       if(a[mid] < x)
38       {
39         l = mid + 1;
40       }else {
41         r = mid - 1;
42       }
43     }
44     return l;
45 }
46 int main(){
47   scanf("%d",&n);
48   for(int i =1 ;i <= n;i ++)
49   {      scanf("%d",&a[i]);
50       a[i] = a[i-1] + a[i];
51   }
52   scanf("%d",&m);
53   for(int i =1 ;i <= m;i ++)
54   {
55       scanf("%d",&b[i]);
56       printf("%d\n",find(b[i]));
57   }
58 return 0;
59 }

C:知道转换公式以后就是一个手速题

  1 // File Name: c.cpp
  2 // Author: darkdream
  3 // Created Time: 2014年10月07日 星期二 00时41分28秒
  4
  5 #include<vector>
  6 #include<list>
  7 #include<map>
  8 #include<set>
  9 #include<deque>
 10 #include<stack>
 11 #include<bitset>
 12 #include<algorithm>
 13 #include<functional>
 14 #include<numeric>
 15 #include<utility>
 16 #include<sstream>
 17 #include<iostream>
 18 #include<iomanip>
 19 #include<cstdio>
 20 #include<cmath>
 21 #include<cstdlib>
 22 #include<cstring>
 23 #include<ctime>
 24 #define LL long long
 25 #define eps 1e-8
 26 using namespace std;
 27 struct node{
 28     double x,y,a,b;
 29 };
 30 node a[5][5];
 31 node  change(node tp)
 32 {
 33    node ans;
 34    ans.a = tp.a;
 35    ans.b = tp.b;
 36    ans.x = tp.a - (tp.y - tp.b);
 37    ans.y = tp.b + (tp.x - tp.a);
 38    return ans;
 39 }
 40 int ans[0];
 41 double dis[5][5];
 42 double thedis(double x1, double y1, double x2,double y2)
 43 {
 44   return sqrt((x1-x2)*(x1-x2) + (y1-y2)*(y1-y2)) ;
 45 }
 46 int mi;
 47 bool ok()
 48 {
 49    node tt[5];
 50    for(int i = 1;i <= 4;i ++)
 51    {
 52       tt[i] = a[i][ans[i]];
 53    }
 54    for(int i = 1;i <= 4;i ++)
 55    {
 56        for(int j= 1;j <= 4 ; j ++)
 57        {
 58             dis[i][j] = thedis(tt[i].x,tt[i].y,tt[j].x,tt[j].y);
 59        }
 60      sort(dis[i] + 1,dis[i] + 1 + 4);
 61    }
 62    for(int i = 2;i <= 4;i ++)
 63        for(int j = 1;j <= 4; j ++)
 64        {
 65           if(fabs(dis[i][j] - dis[i-1][j]) > eps)
 66               return 0 ;
 67        }
 68    if(fabs(dis[1][4]-0 ) <eps)
 69        return 0 ;
 70    if(fabs(dis[1][3] - dis[1][2]) > eps)
 71        return 0 ;
 72    if(fabs(dis[1][3] * sqrt(2) - dis[1][4]) > eps)
 73        return 0 ;
 74    if(fabs(dis[1][3] - 0 ) < eps)
 75        return 0 ;
 76    if(fabs(dis[1][2] - 0 ) < eps)
 77        return 0 ;
 78    /*for(int i = 1;i <= 4;i ++)
 79    {
 80        for(int j = 1;j <= 4; j ++)
 81            printf("%lf ",dis[i][j]);
 82        printf("\n");
 83    }
 84    for(int i = 1;i<= 4;i ++)
 85        printf("%lf %lf\n",tt[i].x,tt[i].y);
 86
 87        */
 88    return 1;
 89 }
 90 void dfs(int k)
 91 {
 92    if(k == 5)
 93    {
 94       if(ok())
 95       {
 96         if(ans[1] + ans[2] + ans[3] + ans[4]  - 4< mi)
 97            mi = ans[1] + ans[2] + ans[3] + ans[4] -4;
 98         //printf("%d %d %d %d\n",ans[1],ans[2],ans[3],ans[4]);
 99       }
100       return;
101    }
102    for(int i = 1;i <= 4;i ++)
103    {
104       ans[k] = i ;
105       dfs(k+1);
106    }
107 }
108 int main(){
109    int n;
110    scanf("%d",&n);
111    while(n--)
112    {
113        for(int i= 1;i <= 4;i ++)
114           scanf("%lf %lf %lf %lf",&a[i][1].x,&a[i][1].y,&a[i][1].a,&a[i][1].b);
115        for(int i = 1;i<= 4;i ++ )
116        {
117           for(int j = 2;j <= 4;j ++)
118               a[i][j] = change(a[i][j-1]);
119        }
120       /* for(int i = 1;i<= 4;i ++ )
121        {
122           for(int j = 1;j <= 4;j ++)
123               printf("%lf %lf ** ",a[i][j].x,a[i][j].y);
124           printf("\n");
125        }*/
126       mi = 1000;
127       dfs(1);
128       if(mi == 1000)
129           printf("-1\n");
130       else printf("%d\n",mi);
131    }
132 return 0;
133 }

D: dp,考虑最后这一位是R还是W即可

 1 // File Name: d.cpp
 2 // Author: darkdream
 3 // Created Time: 2014年10月07日 星期二 00时21分01秒
 4
 5 #include<vector>
 6 #include<list>
 7 #include<map>
 8 #include<set>
 9 #include<deque>
10 #include<stack>
11 #include<bitset>
12 #include<algorithm>
13 #include<functional>
14 #include<numeric>
15 #include<utility>
16 #include<sstream>
17 #include<iostream>
18 #include<iomanip>
19 #include<cstdio>
20 #include<cmath>
21 #include<cstdlib>
22 #include<cstring>
23 #include<ctime>
24 #define LL long long
25 #define maxn 100004
26 #define M 1000000007
27 using namespace std;
28 int t, k ;
29
30 LL ans[maxn][2];
31 LL sum[maxn];
32 int main(){
33   while(scanf("%d %d",&t,&k) != EOF)
34   {
35      ans[1][1] = 1;
36      ans[0][2] = 1;
37
38      if(k == 1 )
39        ans[1][2] = 1;
40      else ans[1][2] = 0 ;
41      sum[0] = 0 ;
42      sum[1] = ans[1][1] + ans[1][2];
43      for(int i = 2; i <= 100000;i ++)
44      {
45          ans[i][1] = (ans[i-1][1] + ans[i-1][2])%M ;
46          if(i >= k )
47            ans[i][2] = (ans[i-k][1] + ans[i-k][2])%M;
48          else{
49            ans[i][2] = 0 ;
50          }
51          sum[i] = (sum[i-1] + ans[i][1] + ans[i][2])%M;
52     //    printf("%I64d\n",sum[i]);
53      }
54      int a, b;
55      for(int i =1 ;i <= t;i ++)
56      {
57        scanf("%d %d",&a,&b);
58        printf("%I64d\n",((sum[b] - sum[a-1])+ M)%M );
59      }
60
61   }
62 return 0;
63 }

时间: 2024-08-04 15:38:43

Codeforces 474(#270) 解题报告的相关文章

codeforces 499B.Lecture 解题报告

题目链接:http://codeforces.com/problemset/problem/499/B 题目意思:给出两种语言下 m 个单词表(word1, word2)的一一对应,以及 professor's lecture 的 n 个单词.问记下来的笔记是什么.对于professor's lecture 的某个单词,如果在单词表中找到,word1, word2 都有可能.如果 word1 的长度  <= word2 的长度,就输出word1,否则word2 考了map<string, st

codeforces 490B.Queue 解题报告

题目链接:http://codeforces.com/problemset/problem/490/B 题目意思:给出每个人 i 站在他前面的人的编号 ai 和后面的人的编号 bi.注意,排在第一个位置的人他前面是无人的!于是 a1 = 0.最后那个人的后面是木有人的,即 bn = 0.然后根据这些条件求出整个序列是如何排的,输出答案. 这条题卡了好久.........啊........啊........啊 首先很容易知道第二个位置的人的编号 和 倒数第二个人的位置编号.用一个aft[]数组记录

Codeforces #263 div2 解题报告

比赛链接:http://codeforces.com/contest/462 这次比赛的时候,刚刚注册的时候很想好好的做一下,但是网上喝了个小酒之后,也就迷迷糊糊地看了题目,做了几题,一觉醒来发现rating掉了很多,那个心痛啊! 不过,后来认真的读了题目,发现这次的div2并不是很难! 官方题解:http://codeforces.com/blog/entry/13568 A. Appleman and Easy Task 解析: 一个水题,判断每个细胞周围是否都是有偶数个相邻细胞.   代码

codeforces 495C. Treasure 解题报告

题目链接:http://codeforces.com/problemset/problem/495/C 题目意思:给出一串只有三种字符( ')','(' 和 '#')组成的字符串,每个位置的这个字符 '#'可以替换成不少于 1 个的 ')',问如何对每个'#'进行替换,使得对于字符串的任意一个位置, ')' 的数量始终不大于'(' 的数量.注意,'#'被替换成')'的总数以及原先有的')'的数量之和 == '(' 的总数. 花了两个晚上的一点时间,今天在图书馆里终于想到解决方案了,大感动 ~~~

Codeforces Round #513解题报告(A~E)By cellur925

我是比赛地址 A:Phone Numbers $Description$:给你一串数字,问你能组成多少开头为8的11位电话号码. $Sol$:统计8的数量,与$n$%11作比较. 1 #include<cstdio> 2 #include<algorithm> 3 #include<cstring> 4 5 using namespace std; 6 7 int n,len,cnt,ans; 8 char ch[1000]; 9 10 int main() 11 {

Codeforces Round #301 解题报告

感觉这次的题目顺序很不合理啊... A. Combination Lock Scrooge McDuck keeps his most treasured savings in a home safe with a combination lock. Each time he wants to put there the treasures that he's earned fair and square, he has to open the lock. The combination loc

Codeforces Round #302 解题报告

感觉今天早上虽然没有睡醒但是效率还是挺高的... Pas和C++换着写... 544A. Set of Strings You are given a string q. A sequence of k strings s1, s2, ..., sk is called beautiful, if the concatenation of these strings is string q(formally, s1 + s2 + ... + sk = q) and the first chara

解题报告 之 CodeForces 91B Queue

解题报告 之 CodeForces 91B Queue Description There are n walruses standing in a queue in an airport. They are numbered starting from the queue's tail: the 1-st walrus stands at the end of the queue and the n-th walrus stands at the beginning of the queue.

codeforces 505A. Mr. Kitayuta&#39;s Gift 解题报告

题目链接:http://codeforces.com/problemset/problem/505/A 题目意思:给出一个长度不大于10的小写英文字符串 s,问是否能通过在字符串的某个位置插入一个字母,使得新得到的字符串成为回文串. /**************************************(又到自我反省时刻) 做的时候,通过添加一个单位使得长度增加1,找出中点,检验前一半的位置,找出对称位置替换成对应的前一半位置的字符,然后原字符串剩下的部分追加到后面,再判断回文.但是由于