Codeforces Beta Round #25 (Div. 2)--A. IQ test
2 seconds
256 megabytes
standard input
standard output
Bob is preparing to pass IQ test. The most frequent task in this test is to find out which one of the given n numbers differs from the others. Bob observed
that one number usually differs from the others in evenness. Help Bob — to check his answers, he needs a program that among the given n numbers finds one
that is different in evenness.
The first line contains integer n (3 ≤ n ≤ 100) —
amount of numbers in the task. The second line contains n space-separated natural numbers, not exceeding 100. It is guaranteed, that exactly one of these
numbers differs from the others in evenness.
Output index of number that differs from the others in evenness. Numbers are numbered from 1 in the input order.
5
2 4 7 8 10
3
4
1 2 1 1
2
解题报告:水题。。
。给你一列数,当中仅仅有一个数的奇偶性和其它数不同,输出它所在的位置。直接暴力扫一遍,记录最后一个奇数和偶数的位置,并记录奇数和偶数的个数。就可以。
AC代码:
#include <stdio.h>
#include <string.h>
#include <iostream>
#include <algorithm>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <string>
#include <math.h>
#include <stdlib.h>
#include <time.h>
using namespace std;
#define INF 0x7fffffff int a[105]; int main()
{
#ifdef sxk
freopen("in.txt","r",stdin);
#endif
int n;
while(scanf("%d",&n)!=EOF)
{
int ans1 = 0, ans2 = 0, x, y;
for(int i=0; i<n; i++){
cin>>a[i];
if(a[i]&1) {
ans1 ++;
x = i+1;
}
else{
ans2 ++;
y = i+1;
}
}
if(ans1>ans2) cout<<y<<endl; //推断条件也可换成ans1 == 1
else cout<<x<<endl;
}
return 0;
}
Codeforces Beta Round #25 (Div. 2)--A. IQ test的更多相关文章
- Codeforces Beta Round #25 (Div. 2 Only)
Codeforces Beta Round #25 (Div. 2 Only) http://codeforces.com/contest/25 A #include<bits/stdc++.h ...
- codeforces水题100道 第十七题 Codeforces Beta Round #25 (Div. 2 Only) A. IQ test (brute force)
题目链接:http://www.codeforces.com/problemset/problem/25/A题意:在n个书中找到唯一一个奇偶性和其他n-1个数不同的数.C++代码: #include ...
- Codeforces Beta Round #25 (Div. 2 Only) A. IQ test【双标记/求给定数中唯一的奇数或偶数】
A. IQ test time limit per test 2 seconds memory limit per test 256 megabytes input standard input ou ...
- Codeforces Beta Round #25 (Div. 2 Only)E. Test
E. Test time limit per test 2 seconds memory limit per test 256 megabytes input standard input outpu ...
- Codeforces Beta Round #25 (Div. 2 Only)D. Roads not only in Berland
D. Roads not only in Berland time limit per test 2 seconds memory limit per test 256 megabytes input ...
- Codeforces Beta Round #25 (Div. 2 Only) C. Roads in Berland
C. Roads in Berland time limit per test 2 seconds memory limit per test 256 megabytes input standard ...
- Codeforces Beta Round #83 (Div. 1 Only)题解【ABCD】
Codeforces Beta Round #83 (Div. 1 Only) A. Dorm Water Supply 题意 给你一个n点m边的图,保证每个点的入度和出度最多为1 如果这个点入度为0 ...
- Codeforces Beta Round #49 (Div. 2)
Codeforces Beta Round #49 (Div. 2) http://codeforces.com/contest/53 A #include<bits/stdc++.h> ...
- Codeforces Beta Round #80 (Div. 2 Only)【ABCD】
Codeforces Beta Round #80 (Div. 2 Only) A Blackjack1 题意 一共52张扑克,A代表1或者11,2-10表示自己的数字,其他都表示10 现在你已经有一 ...
随机推荐
- 【重点突破】—— 当better-scroll 遇见Vue
前言:在学习黄轶老师的<Vue.js高仿饿了么外卖App>课程中接触到了better-scroll第三方JavaScript组件库,这是黄轶老师自己基于iscroll重写的库.这里结合黄轶 ...
- Sublime Theme
Package Control Messages======================== Theme - Spacegray----------------- Thanks for insta ...
- iOS 调用第三方地图进行导航
//支持的地图 { _model = model; //支持的地图 NSMutableArray *maps = [NSMutableArray array]; //苹果原生地图-苹果原生地图方法和其 ...
- hdu 4723 How Long Do You Have to Draw(贪心)
How Long Do You Have to Draw Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K ( ...
- c++ vector容器的使用,序列倒叙reverse(),容器底部插入一个数值push_back()
问题:程序实现将que[i]添加到que2最后,再将que2反转输出. 例如: 输入 4 1 2 3 4 输出 4 2 1 3 #include<iostream> #include< ...
- Android AIDL Service 跨进程传递复杂数据
黑夜 黑夜给了我黑色的眼睛,我却用它寻找光明~ 传值方式 AIDL是同意跨进程传递值的,一般来说有三种方式: - 广播:这样的算是比較常见的一种方式了,传递小数据不错 - 文件:这个是保存到文件里.然 ...
- http协议---简述
http(Hypertext transfer protocol)超文本传输协议,通过浏览器和服务器进行数据交互,进行超文本(文本.图片.视频等)传输的规定. 也就是说,http协议规定了超文本传输所 ...
- opengl剪裁空间和视口空间中不遵从右手定则,而是遵从左手定则
opengl剪裁空间和视口空间中不遵从右手定则,而是遵从左手定则. 比如说要在视口空间判断一个三角形是否是正面朝向用户,就需要用左手定则而非右手定则.
- Java 8 Lambda表达式介绍
Lambda是什么? Lambda是一个匿名函数,我们可以把Lambda理解为是一段可以传递的代码.可以写出简洁.灵活的代码.作为一种更紧凑的代码风格,使java的语言表达能力得到提升. 可以这么说l ...
- Atitit.互联网 软件编程 数据库方面 架构 大牛 牛人 attilax总结
Atitit.互联网 软件编程 数据库方面 架构 大牛 牛人 attilax总结 Coolshell 称号.理论与c++ 阮一峰:: 理论高手与js高手 王银:理论高手 赵劼,网名老赵,c#高手 与理 ...