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]区间的 ...
随机推荐
- wordpress系列1:安装
https://wordpress.org/download/release-archive/ 官方中文网站:https://cn.wordpress.org/ readme.html文件,可查看Wo ...
- warez世界顶级压缩作品网站
http://www.pouet.net/ warez世界顶级压缩作品网站
- 【BZOJ4296】[PA2015]Mistrzostwa BFS
[BZOJ4296][PA2015]Mistrzostwa Description 给定一张n个点m条边的无向图,请找到一个点数最多的点集S,满足:1.对于点集中任何一个点,它至少与d个点集中的点相邻 ...
- CentOS 7 yum安装路径查询方法
先执行下面的命令,查看所有的已安装软件名称. rpm -qa 然后执行 rpm -ql 软件名称 就可以显示软件的安装路径.
- EasyRTMP视频直播推送H264 sps解析错误导致播放画面拉伸问题解决
EasyRTMP是将H264流以及AAC流以RTMP协议推送到RTMP服务器上进行直播.EasyRTMP推送库中会从H264流中提取中SPS.PPS进行解析,开发的时候遇到过有些SPS解析有误,获取到 ...
- Linux就该这么学--命令集合1(常用系统工作命令)
1.用echo命令查看SHELL变量的值(前面有$符号): echo $SHELL 2.查看本机主机名: echo $HOSTNAME 3.查看当前的系统时间: date 4.按照“年-月-日 时:分 ...
- [通信]Linux User层和Kernel层常用的通信方式
转自:https://bbs.csdn.net/topics/390991551?page=1 netlink:https://blog.csdn.net/stone8761/article/deta ...
- failed to load AppCompat ActionBar with unkNown error
解决办法: 在AndroidManifest.xml文件中找到 全局样式文件 Theme,如图: 进入到这个文件,在前面增加 "Base".,如图:
- vue中引入百度统计
vue作为单页面的,引入百度统计,需要注意不少. 一.基本的流量统计 在index.html 入口文件中引入百度统计生成的一连串代码: var _hmt = _hmt || []; (function ...
- HihoCoder 1473 : 小Ho的强迫症( 欧几里得 )
描述 小Ho在一条笔直的街道上散步.街道上铺着长度为L的石板,所以每隔L距离就有一条石板连接的缝隙,如下图所示. 小Ho在散步的时候有奇怪的强迫症,他不希望脚踩在石板的缝隙上.(如果小Ho一只脚的脚尖 ...