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 现在你已经有一 ...
随机推荐
- volatile型变量自增操作的隐患
用FindBugs跑自己的项目,报出两处An increment to a volatile field isn't atomic.对应报错的代码例如以下: volatile int num = ...
- edittext SearchView 失去焦点问题
edittext 默认自己主动获取焦点的 并且会出现小键盘非常烦人 <LinearLayout android:id="@+id/focus" ...
- s3c6410 Linux 驱动开发环境搭建
s3c6410 Linux 驱动开发环境搭建 -- 既然你是做Linux开发的,你还用虚拟机? 非常多人都在win下做开发,于是SD_writer.exe之类的烧写工具"大行其道" ...
- Hadoop之Azkaban详解
工作流调度器azkaban1 为什么需要工作流调度系统 1)一个完整的数据分析系统通常都是由大量任务单元组成:shell脚本程序,java程序,mapreduce程序.hive脚本等 2)各任务单元之 ...
- LVS负载均衡之NAT模式部署
1.LVS的NAT模式介绍 参考自官网:http://www.linuxvirtualserver.org/zh/lvs3.html 由于IPv4中IP地址空间的日益紧张和安全方面的原因,很多网络使用 ...
- java web--百度百科
Java Web,是用Java技术来解决相关web互联网领域的技术总和.web包括:web服务器和web客户端两部分.Java在客户端的应用有java applet,不过使用得很少,Java在服务器端 ...
- js比较数字相等
示例代码: <!DOCTYPE html> <html lang="zh"> <head> <meta charset="UTF ...
- WP8控件进度条(ProgressBar)的使用
--前台代码 <Grid x:Name="ContentPanel" Grid.Row="1" Margin="0,0,24,0"& ...
- python学习笔记之pdb调试
之前一直说要学python可还是一直停留在看的层面,昨天大神手把书教我pdb调试,说要摆脱IDE集成开发环境编程,感激不尽,立一个flag,python一定要入门! 1.进入方式 1)windows ...
- requireJS目录
前言 对于像我这种requireJS初学者而言,requireJS最难理解的部分应该是它的路径问题.晚上随便折腾了一下,算是稍微理清了这个目录问题吧. requireJS学习网址:requireJS中 ...