Rumah >hujung hadapan web >html tutorial >Codeforces Round #271 (Div. 2) 解题报告_html/css_WEB-ITnose
题目地址:http://codeforces.com/contest/474
A题:Keyboard
模拟水题。
代码如下:
#include <iostream>#include <cstdio>#include <string>#include <cstring>#include <stdlib.h>#include <math.h>#include <ctype.h>#include <queue>#include <map>#include <set>#include <algorithm>using namespace std;#define LL __int64char s[]={"qwertyuiopasdfghjkl;zxcvbnm,./"};int main(){ int i, x, j, len; char c, s1[200]; scanf("%c",&c); if(c=='L') x=1; else x=-1; scanf("%s",s1); len=strlen(s1); for(i=0;i<len for if printf s break return> <br> B题:Worms <p></p> <p>水题。。</p> <p>代码如下:</p> <p></p> <pre name="code" class="sycode">#include <iostream>#include <cstdio>#include <string>#include <cstring>#include <stdlib.h>#include <math.h>#include <ctype.h>#include <queue>#include <map>#include <set>#include <algorithm>using namespace std;#define LL __int64int dp[1100000];int main(){ int n, m, i, j, sum=0, x; scanf("%d",&n); for(i=0;i<n scanf for dp sum while printf return> <br> C题: Captain Marmot <p></p> <p>暴力枚举,共4*4*4*4种情况,对每一种情况分别判断是否是正方形。我居然一直都以为是矩形。。</p> <p>判断方法:将4条边与两条对角线分别计算出来。然后排序,4个小的肯定是边,2个大的是对角线,然后判断边是否都相等,对角线是否都相等,对角线是否是边的sqrt(2)倍(这里最好是用平方来判断是否是2倍)。然后找出移动次数最少的输出即可。</p> <p>代码如下:</p> <p></p> <pre name="code" class="sycode">#include <iostream>#include <cstdio>#include <string>#include <cstring>#include <stdlib.h>#include <math.h>#include <ctype.h>#include <queue>#include <map>#include <set>#include <algorithm>using namespace std;#define LL __int64const int mod=1e9+7;struct node{ LL x, y;}t1[5], t2[5], fei[5];node solve(node x, node y, int z){ node t; t=x; int i; for(i=0;i<z x.x="y.y-t.y+y.x;" x.y="t.x-y.x+y.y;" t="x;" return dist a node b ll x="a.x-b.x;" y="a.y-b.y;" judge int i j d sort if main k h min1 scanf while for fei puts else printf> <br> D题:Flowers <p></p> <p>DP,还是水题。。可以这样考虑:</p> <p>第n个只有两种情况,若第n个是R,那么情况数为dp[n-1]种。若第n个是W,由于W只能连续k个,所以说,第n-k+1至第n个必须都是W,那么此时情况数为dp[n-k]种。所以状态转移方程为:</p> <p>dp[n]=dp[n-1]+dp[n-k]。</p> <p>然后用一个数组保存前缀和即可。</p> <p>代码如下:<br> </p> <pre name="code" class="sycode">#include <iostream>#include <cstdio>#include <string>#include <cstring>#include <stdlib.h>#include <math.h>#include <ctype.h>#include <queue>#include <map>#include <set>#include <algorithm>using namespace std;#define LL __int64const int mod=1e9+7;LL dp[110000], sum[110000];int main(){ int i, j, n, k, a, b; LL x=0; sum[0]=0; dp[0]=0; scanf("%d%d",&n,&k); for(i=1;i 自己能做出来的只有这么些。。sad。。 <p></p> </algorithm></set></map></queue></ctype.h></math.h></stdlib.h></cstring></string></cstdio></iostream>