【CodeForces 353 A】Domino
【链接】 我是链接,点我呀:)
【题意】
【题解】
分类讨论一波
设第一个数组的奇数个数为cnt1
第二个数组的奇数个数为cnt2
显然只有在(cnt1+cnt2)%2==0的情况下。
才可能第一个数组的和为偶数,第二个数组的和也为偶数
(因为奇数都要出现偶数次才可以。
所以只可能cnt1和cnt2都是偶数,那么输出0
否则,cnt1和cnt2都是奇数,看看有没有一个位置i只有a[i]或只有b[i]是奇数。有的话输出1.
其他情况都非法。
【代码】
#include <bits/stdc++.h>
using namespace std;
const int N = 1e2;
int n;
int x[N+10],y[N+10],cnt1,cnt2;
int main()
{
#ifdef LOCAL_DEFINE
freopen("rush.txt","r",stdin);
#endif // LOCAL_DEFINE
ios::sync_with_stdio(0),cin.tie(0);
cin >> n;
for (int i = 1;i <= n;i++){
cin >> x[i] >> y[i];
if (x[i]&1) cnt1++;
if (y[i]&1) cnt2++;
}
if (cnt1%2==0 && cnt2%2==0){
cout<<0<<endl;
}else if ( (cnt1+cnt2)%2 != 0){
cout<<-1<<endl;
}else{
//cnt1+cnt2 == not odd
for (int i = 1;i <= n;i++){
if (x[i]&1 && y[i]%2==0)
return cout<<1<<endl,0;
if (x[i]%2==0 && y[i]&1)
return cout<<1<<endl,0;
}
cout<<-1<<endl;
}
return 0;
}
【CodeForces 353 A】Domino的更多相关文章
- 【Codeforces Rockethon 2014】Solutions
转载请注明出处:http://www.cnblogs.com/Delostik/p/3553114.html 目前已有[A B C D E] 例行吐槽:趴桌子上睡着了 [A. Genetic Engi ...
- 【57.97%】【codeforces Round #380A】Interview with Oleg
time limit per test1 second memory limit per test256 megabytes inputstandard input outputstandard ou ...
- 【42.86%】【Codeforces Round #380D】Sea Battle
time limit per test1 second memory limit per test256 megabytes inputstandard input outputstandard ou ...
- 【26.83%】【Codeforces Round #380C】Road to Cinema
time limit per test1 second memory limit per test256 megabytes inputstandard input outputstandard ou ...
- 【17.76%】【codeforces round 382C】Tennis Championship
time limit per test2 seconds memory limit per test256 megabytes inputstandard input outputstandard o ...
- 【21.21%】【codeforces round 382D】Taxes
time limit per test2 seconds memory limit per test256 megabytes inputstandard input outputstandard o ...
- 【50.88%】【Codeforces round 382B】Urbanization
time limit per test2 seconds memory limit per test256 megabytes inputstandard input outputstandard o ...
- 【Codeforces Round 650】Codeforces #334 (Div. 1)
模拟CF650,ABC三题,RK90 Codeforces 650 A 思路:首先看式子 \(\sqrt{(x_i-x_j)^2+(y_i-y_j)^2}=|x_i-x_j|+|y_i-y_j|\) ...
- 【Codeforces Round 725】Canada Cup 2016
模拟Canada Cup 2016,ABC三题,Rank1376 第三题卡住了 Codeforces 725 C 求出两个相同字符的位置,记为x和y. 然后考虑把相同的那个字符放在第一行的什么地方, ...
随机推荐
- PowerPC汇编指令集
PowerPC 体系结构规范(PowerPC Architecture Specification)公布于 1993 年,它是一个 64位规范 ( 也包括 32 位子集 ).差点儿全部常规可用的 Po ...
- no projects are found to import
从svn上导出的项目在导入Eclipse中常常出现 no projects are found to import . 产生的原因是:项目文件里中没有".classpath"和&q ...
- android 百度地图 定位功能
废话不多说 直接新建一个新android项目:location,然后花一分钟申请一个key,然后就是把百度定位demo抄一下即可 1:首先在AndroidManifest.xml中加入权限 <u ...
- ant 调用
博客园 首页 新随笔 联系 订阅 管理 [图文] 使用ant编译和发布java项目 开发JavaEE项目经常会碰到修改代码后,项目没有重新编译的问题.老大给指明了一个解决办法:用ant ...
- luogu2437 蜜蜂路线
题目大意 一只蜜蜂在下图所示的数字蜂房上爬动,已知它只能从标号小的蜂房爬到标号大的相邻蜂房,现在问你:蜜蜂从蜂房M开始爬到蜂房N,M<N,有多少种爬行路线?M,N<=1000 题解 看到M ...
- luogu3386 【模板】 二分图匹配
基本概念:二分图有两种节点:X节点和Y节点.如果X和Y可以匹配, 则X与Y连着一条边.每个X节点最多只能匹配一个Y节点,同时每个Y节点最多只能匹配一个X节点.最大匹配便是最多的匹配数. 交错路径:交错 ...
- yolo源码解析(3):视频检测流程
代码在自己电脑中!!!!不在服务器 根据前文所说yolo代码逻辑: ├── examples │ ├── darknet.c(主程序) │ │── xxx1.c │ └── xxx2.c │ ├── ...
- CodeForces 486B
Let's define logical OR as an operation on two logical values (i. e. values that belong to the set { ...
- 【POJ 2976】 Dropping Tests
[题目链接] http://poj.org/problem?id=2976 [算法] 0/1分数规划 [代码] #include <algorithm> #include <bits ...
- php如何将网上的图片下载到本地
<?phpheader("Content-Type: application/force-download");header("Content-Dispositio ...