Codeforces Round #271 (Div. 2) 解题报告
题目地址: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 __int64
char 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;i++)
{
for(j=0;;j++)
{
if(s[j]==s1[i])
{
printf("%c", s[j+x]);
break;
}
}
}
return 0;
}
B题:Worms
水题。。
代码例如以下:
#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 __int64
int dp[1100000];
int main()
{
int n, m, i, j, sum=0, x;
scanf("%d",&n);
for(i=0;i<n;i++)
{
scanf("%d",&x);
for(j=sum;j<sum+x;j++)
{
dp[j]=i;
}
sum+=x;
}
scanf("%d",&m);
while(m--)
{
scanf("%d",&x);
printf("%d\n",dp[x-1]+1);
}
return 0;
}
C题:Captain Marmot
暴力枚举,共4*4*4*4种情况。对每一种情况分别推断是否是正方形。
我竟然一直都以为是矩形。。
推断方法:将4条边与两条对角线分别计算出来。然后排序,4个小的肯定是边,2个大的是对角线,然后推断边是否都相等,对角线是否都相等,对角线是否是边的sqrt(2)倍(这里最好是用平方来推断是否是2倍)。然后找出移动次数最少的输出就可以。
代码例如以下:
#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 __int64
const 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;i++)
{
x.x=y.y-t.y+y.x;
x.y=t.x-y.x+y.y;
t=x;
}
return t;
}
LL dist(node a, node b)
{
LL x=a.x-b.x;
LL y=a.y-b.y;
return x*x+y*y;
}
bool judge()
{
int i, j;
LL d[6];
d[0]=dist(fei[0],fei[1]);
d[1]=dist(fei[1],fei[2]);
d[2]=dist(fei[2],fei[3]);
d[3]=dist(fei[3],fei[0]);
d[4]=dist(fei[0],fei[2]);
d[5]=dist(fei[1],fei[3]);
sort(d,d+6);
if(d[0]==0) return 0;
if(d[0]==d[1]&&d[1]==d[2]&&d[2]==d[3]&&d[4]==2*d[0]&&d[4]==d[5])
return 1;
return 0;
}
int main()
{
int t, i, j, k, h, min1;
scanf("%d",&t);
while(t--)
{
min1=20;
for(i=0;i<4;i++)
{
scanf("%I64d%I64d%I64d%I64d",&t1[i].x,&t1[i].y,&t2[i].x,&t2[i].y);
}
for(i=0;i<4;i++)
{
fei[0]=solve(t1[0],t2[0],i);
for(j=0;j<4;j++)
{
fei[1]=solve(t1[1],t2[1],j);
for(k=0;k<4;k++)
{
fei[2]=solve(t1[2],t2[2],k);
for(h=0;h<4;h++)
{
fei[3]=solve(t1[3],t2[3],h);
if(judge())
{
min1=min(min1,i+j+k+h);
}
}
}
}
}
if(min1==20) puts("-1");
else
printf("%d\n",min1);
}
return 0;
}
D题:Flowers
DP。还是水题。。能够这样考虑:
第n个仅仅有两种情况。若第n个是R。那么情况数为dp[n-1]种。若第n个是W,因为W仅仅能连续k个,所以说,第n-k+1至第n个必须都是W,那么此时情况数为dp[n-k]种。
所以状态转移方程为:
dp[n]=dp[n-1]+dp[n-k]。
然后用一个数组保存前缀和就可以。
代码例如以下:
#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 __int64
const 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<=k-1;i++)
dp[i]=1;
dp[k]=2;
for(i=k+1;i<=100000;i++)
{
dp[i]=dp[i-k]+dp[i-1];
dp[i]%=mod;
}
for(i=1;i<=100000;i++)
{
sum[i]=(sum[i-1]+dp[i])%mod;
}
while(n--)
{
scanf("%d%d",&a,&b);
printf("%I64d\n",(sum[b]+mod-sum[a-1])%mod);
}
return 0;
}
自己能做出来的仅仅有这么些。。
sad。
。
Codeforces Round #271 (Div. 2) 解题报告的更多相关文章
- Codeforces Round #324 (Div. 2)解题报告
---恢复内容开始--- Codeforces Round #324 (Div. 2) Problem A 题目大意:给二个数n.t,求一个n位数能够被t整除,存在多组解时输出任意一组,不存在时输出“ ...
- Codeforces Round #382 (Div. 2) 解题报告
CF一如既往在深夜举行,我也一如既往在周三上午的C++课上进行了virtual participation.这次div2的题目除了E题都水的一塌糊涂,参赛时的E题最后也没有几个参赛者AC,排名又成为了 ...
- Codeforces Round #380 (Div. 2) 解题报告
第一次全程参加的CF比赛(虽然过了D题之后就开始干别的去了),人生第一次codeforces上分--(或许之前的比赛如果都参加全程也不会那么惨吧),终于回到了specialist的行列,感动~.虽然最 ...
- Codeforces Round #216 (Div. 2)解题报告
又范低级错误! 只做了两题!一道还被HACK了,囧! A:看了很久!应该是到语文题: 代码:#include<iostream> #include<]; ,m2=; ;i ...
- Codeforces Round #281 (Div. 2) 解题报告
题目地址:http://codeforces.com/contest/493 A题 写完后就交了,然后WA了,又读了一遍题,没找出错误后就开始搞B题了,后来回头重做的时候才发现,球员被红牌罚下场后还可 ...
- Codeforces Round #277 (Div. 2) 解题报告
题目地址:http://codeforces.com/contest/486 A题.Calculating Function 奇偶性判断,简单推导公式. #include<cstdio> ...
- Codeforces Round #276 (Div. 2) 解题报告
题目地址:http://codeforces.com/contest/485 A题.Factory 模拟.判断是否出现循环,如果出现,肯定不可能. 代码: #include<cstdio> ...
- Codeforces Round #350 (Div. 2)解题报告
codeforces 670A. Holidays 题目链接: http://codeforces.com/contest/670/problem/A 题意: A. Holidays On the p ...
- Codeforces Round #479 (Div. 3)解题报告
题目链接: http://codeforces.com/contest/977 A. Wrong Subtraction 题意 给定一个数x,求n次操作输出.操作规则:10的倍数则除10,否则减1 直 ...
随机推荐
- 常见的版本号及Springcloud的版本
谈谈软件版本号的认识 一.常见版本号说明 举个瓜:2.0.3 RELEASE 2:主版本号,当功能模块有较大更新或者整体架构发生变化时,主版本号会更新 0:次版本号.次版本表示只是局部的一些变动. 2 ...
- 6.between...and...
6.在WHERE中使用between...and... 用于区间值的条件判断(包含边界值) //查询工资在2000(包含)到3000(包含)之间的员工信息 select empno,e ...
- org.apache.hadoop.ipc.Client: Retrying connect to server
这个问题导致jps查看结点进程时发现找不到NodeManager或一段时间后消失,网上查找了很多博客,因hadoop版本不一样且出错的原因也可能不同,所以找了老半天. 步骤:jps --> 看l ...
- ASP.NET-js和C#混合编程的例子
使用<text>这个伪元素来强制Razor从编译模式返回到内容模式: 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 ...
- Android.mk添加本地程序和库的经常使用模版
Android.mk添加本地程序和库的经常使用模版 Android中添加本地程序或者库.这些程序和库与其所在路径没有关系.仅仅与它们的配置文件Android.mk有关.Android.mk文件里可以主 ...
- Linux防火墙限制指定port仅仅能由指定IP訪问
须要对redis的端口做限制,仅仅能让公司内指定IP的机器訪问 -A INPUT -m state --state NEW -m tcp -p tcp --dport 22 -j ACCEPT -A ...
- 嵌入式外部中断控制编程方法论—比較CC2541(51核)和S5PV210(ARM核)
这是一篇阐述怎样对嵌入式SOC外部中断进行控制编程的方法论文章.希望读者理解本篇文章后.能够具备对市场上全部已经面世和将来面世的嵌入式芯片的外部中断进行控制编程的能力. 笔者原创的技术分享一直都恪守下 ...
- angular4(3)angular脚手架引入scss
scss..sass....sccc...ssss...ccccc......MMP················· 先说下scss和sass的异同: SCSS 是 Sass 3 引入新的语法,其语 ...
- 大量文件时使用ls
有时一个目录下的文件实在太多, ls的时候就卡住了. 其实, 如果不加排序的话, 就可以迅速的显示文件. ls -f 解释: -f do not sort, enable -aU, disable - ...
- LeetCode 190. Reverse Bits (算32次即可)
题目: 190. Reverse Bits Reverse bits of a given 32 bits unsigned integer. For example, given input 432 ...