CodeForces水题
CodeForces754A
题意:
给一个数组,让你变成1-n,输出变换区间,要求原区间和不为0.
思路:
如果原数组不为0,那就是YES;
如果为0,则从1开始扫过去,碰到不为0时,分两个区间[1,k],[k+1,n]
#include<bits/stdc++.h>
using namespace std; int a[110]; int main()
{
int n,i,sum;
while(~scanf("%d",&n))
{
sum=0;
for(i=1;i<=n;i++)
{
scanf("%d",&a[i]);
sum+=a[i];
}
if(sum==0)
{
sum=0;
for(int s=1;s<=n;s++)
{
sum+=a[s];
if(sum)
{
if(s!=n)
{
puts("YES");
puts("2");
printf("%d %d\n",1,s);
printf("%d %d\n",s+1,n);
}
else
{
puts("YES");
printf("%d %d\n",1,n);
}
return 0;
}
}
puts("NO");
}
else
{
puts("YES");
puts("1");
printf("%d %d\n",1,n);
}
}
return 0;
}
CodeForces754B
题意:
'.' (empty cell),
'x' (lowercase English letter x),
'o' (lowercase English letter o).
horizontal, vertical or diagonal有3个获胜,问能否在一部内使得有x在horizontal, vertical or diagonal连成3个。
思路:
暴力枚举horizontal, vertical or diagonal?
#include<bits/stdc++.h>
using namespace std; char ma[5][5]; bool manzu(int x)
{
if(x>=0&&x<4)
return true;
return false;
} bool judge_three(int sx,int sy,int ex,int ey)
{
int num1,num2;
int i,j;
num1=num2=0;
for(i=sx,j=sy;;)
{
if(ma[i][j]=='x') num1++;
if(ma[i][j]=='.') num2++;
if(i==ex&&j==ey)
break;
if(i<ex) i++;
if(j<ey) j++;
}
if(num1==2&&num2==1)
return true;
return false;
} bool Judge(int x,int y)
{
if(manzu(x+2))
if(judge_three(x,y,x+2,y)) return true;
if(manzu(x-2))
if(judge_three(x-2,y,x,y)) return true;
if(manzu(y+2))
if(judge_three(x,y,x,y+2)) return true;
if(manzu(y-2))
if(judge_three(x,y-2,x,y)) return true;
if(manzu(x+2)&&manzu(y+2))
if(judge_three(x,y,x+2,y+2)) return true;
if(manzu(x-2)&&manzu(y-2))
if(judge_three(x-2,y-2,x,y)) return true;
if(manzu(x+2)&&manzu(y-2))
{
int num1=0,num2=0;
if(ma[x][y]=='x') num1++;
if(ma[x][y]=='.') num2++;
if(ma[x+1][y-1]=='x') num1++;
if(ma[x+1][y-1]=='.') num2++;
if(ma[x+2][y-2]=='x') num1++;
if(ma[x+2][y-2]=='.') num2++;
if(num1==2&&num2==1) return true;
}
if(manzu(x-2)&&manzu(y+2))
{
int num1=0,num2=0;
if(ma[x][y]=='x') num1++;
if(ma[x][y]=='.') num2++;
if(ma[x-1][y+1]=='x') num1++;
if(ma[x-1][y+1]=='.') num2++;
if(ma[x-2][y+2]=='x') num1++;
if(ma[x-2][y+2]=='.') num2++;
if(num1==2&&num2==1) return true;
}
return false;
} int main()
{
for(int i=0; i<4; i++)
scanf("%s",ma[i]);
for(int i=0;i<4;i++)
for(int j=0;j<4;j++)
if(Judge(i,j))
{
puts("YES");
return 0;
}
puts("NO");
return 0;
}
/*
o.x.
o...
.x..
ooxx
*/
CodeForces599A
题意:
d1 is the length of the path house and first shop;
d2 is the length of the path house and second shop;
d3 is the length of the path both shops.
思路:
显然水题
#include<bits/stdc++.h>
using namespace std; int a[110]; int main()
{
int num=0;
int d1,d2,d3;
scanf("%d%d%d",&d1,&d2,&d3);
a[num++]=d1+d2+d3;
a[num++]=2*(d1+d2);
a[num++]=2*(d1+d3);
a[num++]=2*(d2+d3);
sort(a,a+num);
printf("%d\n",a[0]);
return 0;
}
CodeForces599B
题意:
给出f[],b[];
构造ai, 使得 b[i]=f[ai]
只有一组则直接输出
有多种情况输出"Ambiguity"
如果不可能就是不可能
思路:
直接模拟。
先搞出impossible的情况,也就是没有匹配的,其次看是不是存在多个的。
然后就是输出坐标就好了。
#include<bits/stdc++.h>
using namespace std; const int N=1e5+10;
int index[N];
int f[N],a[N],n,m;
int num[N];
bool flag,flat; int main()
{
scanf("%d%d",&n,&m);
memset(num,0,sizeof(num));
for(int i=1;i<=n;i++)
{
scanf("%d",&f[i]);
index[f[i]]=i;
num[f[i]]++;
}
flag=false;
flat=false;
for(int i=1;i<=m;i++)
{
scanf("%d",&a[i]);
if(!num[a[i]])
flag=true;
if(num[a[i]]>1)
flat=true;
}
if(flag)
puts("Impossible");
else if(flat)
puts("Ambiguity");
else
{
puts("Possible");
for(int i=1;i<=m;i++)
printf("%d ",index[a[i]]);
}
return 0;
}
CodeForces水题的更多相关文章
- Codeforces水题集合[14/未完待续]
Codeforces Round #371 (Div. 2) A. Meeting of Old Friends |B. Filya and Homework A. Meeting of Old Fr ...
- codeforces水题100道 第二十七题 Codeforces Round #172 (Div. 2) A. Word Capitalization (strings)
题目链接:http://www.codeforces.com/problemset/problem/281/A题意:将一个英文字母的首字母变成大写,然后输出.C++代码: #include <c ...
- codeforces水题100道 第二十六题 Codeforces Beta Round #95 (Div. 2) A. cAPS lOCK (strings)
题目链接:http://www.codeforces.com/problemset/problem/131/A题意:字符串大小写转换.C++代码: #include <cstdio> #i ...
- codeforces水题100道 第二十五题 Codeforces Round #197 A. Helpful Maths (Div. 2) (strings)
题目链接:http://www.codeforces.com/problemset/problem/339/A题意:重新组合加法字符串,使得按照1,2,3的顺序进行排列.C++代码: #include ...
- codeforces水题100道 第二十四题 Codeforces Beta Round #85 (Div. 2 Only) A. Petya and Strings (strings)
题目链接:http://www.codeforces.com/problemset/problem/112/A题意:忽略大小写,比较两个字符串字典序大小.C++代码: #include <cst ...
- codeforces水题100道 第二十三题 Codeforces Beta Round #77 (Div. 2 Only) A. Football (strings)
题目链接:http://www.codeforces.com/problemset/problem/96/A题意:判断一个0-1字符串中出现的最长的0字串或者1字串的长度是否大于等于7.C++代码: ...
- codeforces水题100道 第二十二题 Codeforces Beta Round #89 (Div. 2) A. String Task (strings)
题目链接:http://www.codeforces.com/problemset/problem/118/A题意:字符串转换……C++代码: #include <string> #inc ...
- codeforces水题100道 第二十一题 Codeforces Beta Round #65 (Div. 2) A. Way Too Long Words (strings)
题目链接:http://www.codeforces.com/problemset/problem/71/A题意:将长字符串改成简写格式.C++代码: #include <string> ...
- codeforces水题100道 第二十题 Codeforces Round #191 (Div. 2) A. Flipping Game (brute force)
题目链接:http://www.codeforces.com/problemset/problem/327/A题意:你现在有n张牌,这些派一面是0,另一面是1.编号从1到n,你需要翻转[i,j]区间的 ...
随机推荐
- Nginx+ffmpeg的HLS开源server搭建配置及开发具体解释
本文概述: 至眼下为止.HLS 是移动平台上很重要并十分流行的流媒体传输协议.做移动平台的流媒体开发,不知道它不掌握它 .真是一大遗憾.而HLS的平台搭建有一定的难度,本文针对对该方向有一定了解的朋友 ...
- 【BZOJ2729】[HNOI2012]排队 组合数
[BZOJ2729][HNOI2012]排队 Description 某中学有 n 名男同学,m 名女同学和两名老师要排队参加体检.他们排成一条直线,并且任意两名女同学不能相邻,两名老师也不能相邻,那 ...
- 哈希表的java实现
一.为什么要用哈希表 树的操作通常需要O(N)的时间级,而哈希表中无论存有多少数据,它的插入和查找(有时包括删除)只需要接近常量级的时间,即O(1)的时间级. 但是哈希表也有一定的缺点:它是基于数组的 ...
- lazy evaluation and deferring a computation await promise async
Promise - JavaScript | MDN https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_ ...
- CRM 安装不规范,亲人两行泪
安装CRM需要严格按照CRM部署文档的要求进行,比如设置CRM服务的服务账号一定要加入到CRM所在组织库用户里,不然会遇到下面错误.这个就是传递到SQL 的账号,在SQL那边不识别 <s:Env ...
- Go语言string,int,int64 ,float之间类型转换方法
(1)int转string ? 1 2 s := strconv.Itoa(i) 等价于s := strconv.FormatInt(int64(i), 10) (2)int64转string ? 1 ...
- CSS3学习笔记(1)—淡入的文字
今天有空把前几天学的东西发一下,都是一些简单的东西,但是千里之行始于足下,我虽然走的慢,但是未停下前进的脚步, 下来看下我做的“淡入的文字”最终动态效果: 上面这个动画效果制作的过程是: (1)先自定 ...
- H264 各种profile
关键字:H264 ,base profile, main profile, extend profile, high profile. 提到High Profile H.264解码许多人并不了解,那么 ...
- Android加载/处理超大图片神器!SubsamplingScaleImageView(subsampling-scale-image-view)【系列1】
Android加载/处理超大图片神器!SubsamplingScaleImageView(subsampling-scale-image-view)[系列1] Android在加载或者处理超大巨型图片 ...
- html5--5-1 了解canvas元素
html5--5-1 了解canvas元素 学习要点 如何在HTML5文档中添加canvas元素 canvas的属性 了解canvas坐标系 了解script元素 绘制一条直线(准确的说是线段) 什么 ...