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]区间的 ...
随机推荐
- 命令行查看memcached的运行状态(转载)
很多时候需要监控服务器上的Memcached运行情况,比如缓存的查询次数,命中率之类的.但找到的那个memcached-tool是linux下用perl写的,我也没试过windows能不能用.后来发现 ...
- 初探IO复用
前言 在之前的文章中,我具体实现了一个并发回射服务器并给它加载了僵尸子进程的自动清理信号机制.在正常情况下,它已经可以很好地工作了,但它能否合理应对一些特殊情况呢? 问题发现 先来看看当服务器的客户子 ...
- cvpr2014
http://www.cvpapers.com/cvpr2014.html 吴佳俊 楼天城
- UNIX网络编程卷1 时间获取程序client TCP 使用非堵塞connect
本文为senlie原创,转载请保留此地址:http://blog.csdn.net/zhengsenlie 1.当在一个非堵塞的 TCP 套接字(可使用 fcntl 把套接字变成非堵塞的)上调用 co ...
- 【BZOJ4296】[PA2015]Mistrzostwa BFS
[BZOJ4296][PA2015]Mistrzostwa Description 给定一张n个点m条边的无向图,请找到一个点数最多的点集S,满足:1.对于点集中任何一个点,它至少与d个点集中的点相邻 ...
- Lombok引入简化Java代码
转载 http://t.cn/RS0UdrX Lombok简介 如Github上项目介绍所言,Lombok项目通过添加“处理程序”,使java成为一种更为简单的语言.作为一个Old Java Deve ...
- a REST API
https://spring.io/guides/tutorials/bookmarks/ http://roy.gbiv.com/untangled/2008/rest-apis-must-be-h ...
- the algebra of modulo-2 sums disk failure recovery
x=y x_+_y=0 The bit in any position is the modulo-2 sum of all the bits in the corresponding positio ...
- Javascript学习之Date对象详解
1.定义 创建 Date 实例用来处理日期和时间.Date 对象基于1970年1月1日世界协调时起的毫秒数 2.语法 构造函数 new Date() new Date(value) value代表自世 ...
- java replaceAll Replace
java ReplaceAll 的两个参数都必须是正则表达式. 在正则表达式中 \ (一个斜线)是用 \\ 来表示(即:用两个斜线表示一个斜线) 而在Java语言中 \ (一个斜线)是用 \\ 来表示 ...