Codeforces Round #271 (Div. 2)
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)的更多相关文章
- Codeforces Round #271 (Div. 2)题解【ABCDEF】
Codeforces Round #271 (Div. 2) A - Keyboard 题意 给你一个字符串,问你这个字符串在键盘的位置往左边挪一位,或者往右边挪一位字符,这个字符串是什么样子 题解 ...
- Codeforces Round #271 (Div. 2) F. Ant colony (RMQ or 线段树)
题目链接:http://codeforces.com/contest/474/problem/F 题意简而言之就是问你区间l到r之间有多少个数能整除区间内除了这个数的其他的数,然后区间长度减去数的个数 ...
- Codeforces Round #271 (Div. 2) D. Flowers (递推)
题目链接:http://codeforces.com/problemset/problem/474/D 用RW组成字符串,要求w的个数要k个连续出现,R任意,问字符串长度为[a, b]时,字符串的种类 ...
- Codeforces Round #271 (Div. 2) E题 Pillars(线段树维护DP)
题目地址:http://codeforces.com/contest/474/problem/E 第一次遇到这样的用线段树来维护DP的题目.ASC中也遇到过,当时也非常自然的想到了线段树维护DP,可是 ...
- Codeforces Round #271 (Div. 2) F题 Ant colony(线段树)
题目地址:http://codeforces.com/contest/474/problem/F 由题意可知,最后能够留下来的一定是区间最小gcd. 那就转化成了该区间内与区间最小gcd数相等的个数. ...
- 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 ...
- Codeforces Round #271 (Div. 2)-A. Keyboard
http://codeforces.com/problemset/problem/474/A A. Keyboard time limit per test 2 seconds memory limi ...
- Codeforces Round #271 (Div. 2) 解题报告
题目地址:http://codeforces.com/contest/474 A题:Keyboard 模拟水题. 代码例如以下: #include <iostream> #include ...
- Codeforces Round #271 (Div. 2) F ,E, D, C, B, A
前言:最近被线段树+简单递推DP虐的体无完肤!真是弱! A:简单题,照着模拟就可以,题目还特意说不用处理边界 B:二分查找即可,用lower_lound()函数很好用 #include<stri ...
随机推荐
- 简单制作mib表
今天放假后第一天上班,将假前自学制作mib表的东西说一下. 在这里呢,我以世界-中国-上海-闵行这种包含关系介绍,感觉更容易理解. MIB file的开始和结束 所有的MIB file的都以DEFIN ...
- 存储过程——在LINQ中使用(六)
上述几篇都将了存储与数据库,关联的一些实例,首先感谢各位大神们在前几篇文章中提到的问题,本人还在学习中,这次介绍下在linq中如何应用存储过程: LINQ简介 语言集成查询(LINQ)在对象领域和数据 ...
- C++拷贝构造函数详解(转载)
一. 什么是拷贝构造函数 首先对于普通类型的对象来说,它们之间的复制是很简单的,例如: int a = 100; int b = a; 而类对象与普通对象不同,类对象内部结构一般较为复杂,存在各种成员 ...
- java 回传参数
通过 new 创建的对象可以实现回传,如数组:自定义类对象里的参数. [数组方式] public static void main(String[] args) { try { int [] amou ...
- JSP访问Spring中的bean
JSP访问Spring中的bean <%@page import="com.sai.comment.po.TSdComment"%> <%@page import ...
- 01-03-02-1【Nhibernate (版本3.3.1.4000) 出入江湖】CRUP操作--cascade 级联相关
要点: 1. <!--双向关联时要用: inverse:由子表来维护关系,cascade:级联的关系 如果没有这个设置, 插入Customer成功(即使现在Order插入Order抛异常,这时产 ...
- jQuery中的&& ||
jQuery1.2.6 clean方法中有这么一段第一眼看去会让人晕掉的方法.完全不知其所言. “||, && 可以这样用?”,“这段东西最终返回的是个什么对象啊?” // Trim ...
- VisionTimer BUG && Start
void Start() { vp_Timer.In(0.0f, delegate() { Debug.Log("Start"); }, 10, 1.0f); } Version ...
- CentOS(RHEL) 操作备忘
1.安装中文语言包及切换 yum groupinstall chinese-support vi /etc/sysconfig/i18n change en_US to zh_CN 2.用户自动登录 ...
- Bad configuration option localCommand
command-line: line 0: Bad configuration option: PermitLocalCommand 2011-12-08 14:04:54 标签:Bad confi ...