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]区间的 ...
随机推荐
- Markov and Chebyshev Inequalities and the Weak Law of Large Numbers
https://www.math.wustl.edu/~russw/f10.math493/chebyshev.pdf http://www.tkiryl.com/Probability/Chapte ...
- Mac 下Java开发环境安装
一.安装Eclipse 1.官网下载安装文件 http://www.eclipse.org/downloads 2.eclipse安装svn插件 这里须要注意安装的svn的版本号.要和后面的安装的Ja ...
- 高速排序及优化(Java版)
高速排序(Quicksort)是对冒泡排序的一种改进. 高速排序由C. A. R. Hoare在1962年提出. 一次高速排序具体过程: 选择数组第一个值作为枢轴值. 代码实现: package Qu ...
- PHP开发工作心得
一.扎实PHP自身的基础知识.函数.常量等,尽量用内置的方法解决这个问题(由于个人写的往往运行效率没有内置方法高): 二.代码尽量少的实现功能(由于PHP的运行事实上是,将咱们的代码先处理成底层语言进 ...
- CentOS 更换 usr 挂载分区
由于之前挂载在/usr目录的分区空间过小,无法安装更多需要的软件,现在添加一块硬盘重新挂载在/usr目录,并将之前/usr 目录下的内容(包括权限.连接等)完整拷贝到新磁盘分区的/usr目录. 操作系 ...
- Unity编译时找不到AndroidSDK的问题 | Unable to list target platforms
解决方式 1.从官网下载一个旧版本的 Android SDK tools 25.2.3.tools_r25.2.3-windows.zip. 2. 解压 3. 替换原来sdk目录下tools
- iOS信号量
引子: 在取本地联系人列表的时候看到同事用的这么一段代码: dispatch_semaphore_t sema = dispatch_semaphore_create(); ABAddressBook ...
- ThinkPHP 静态页缓存
通过对ThinkPHP的学习,记录下静态页的缓存步骤,以便以后查阅: 1.配置配置文件/Admin/Conf/config.php代码如下: /*静态缓存*/ 'HTML_CACHE_ON'=> ...
- ArcGIS服务器的feature图层限制
今天遇到了esri.layers.FeatureLayer发布一个宗地图层,里面有些数据未显示,导致数据显示不全,原来是服务中数据返回参数限制. ArcGIS的feature图层(在JavaScrip ...
- spark uniq 本质上就是单词计数
粗体部分示例: # dns_domain_info_list_rdd ==> [(src_ip, domain, domain_ip, timestamp, metadataid), ....] ...