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 现在你已经有一 ...
随机推荐
- RDD编程 上(Spark自学三)
弹性分布式数据集(简称RDD)是Spark对数据的核心抽象.RDD其实就是分布式的元素集合.在Spark中,对数据的操作不外乎创建RDD.转化已有RDD以及调用RDD操作进行求值.而在这一切背后,Sp ...
- uva 11584 Partitioning by Palindromes 线性dp
// uva 11584 Partitioning by Palindromes 线性dp // // 题目意思是将一个字符串划分成尽量少的回文串 // // f[i]表示前i个字符能化成最少的回文串 ...
- Node.js meitulu图片批量下载爬虫1.03版
//====================================================== // https://www.meitulu.com图片批量下载Node.js爬虫1. ...
- 用table表格来调整控件的格式
由于想自己写一个web,所以也在学习html语言的一些东西,让我回忆起了大学时代曾对网页设计产生过兴趣,无奈那时候还没有自己的电脑,还常去网吧买个软盘下载一些图片,然后用fontpage做一些网页.后 ...
- Memcachedclientutils类
0.个人标签 我的CSDN博客地址: http://blog.csdn.net/caicongyang 1.依赖的jar包 commons-pool-1.5.6.jar slf4j-api-1.6.1 ...
- TMS320F28335项目开发记录1_CCS的使用介绍
CCS使用介绍 一.前言 本系列文章记录本人实际项目开发时对ti的DSP28335,以及CCS开发环境等的学习与记录,相对于2812来说,28335的资料还是比較少的,只是原理是相通的,28335说白 ...
- 炫酷的sublimeText开发工具 快捷键总结
sublimeText3绝对是写前端程序的利器.占内存小.启动快.代码提示功能齐全,界面酷炫并且再也不怕断电.了 网上搜罗一些快捷键总结一下.先来张图: (事实上sublimeText3也能够写 ...
- matlab经常使用小函数(一)
(第1维为对每一列操作.第2维维对每一行操作) sum 求和操作 max 求最大值操作 sum:求和操作 sum(A):矩阵A按列向求和(每一列求和).结果为一个行向量 sum(A,2):矩阵 ...
- Flex开发实战(一)--Flex的具体介绍
背景 因为近期要维护公司的项目,项目里面用到了Flex技术,所以近期一直在恶补.这篇博文就将近期的学习内容,进行一下简单的总结. 不管是做web还是桌面应用.相信大家对于界面的要求已经越来越高.界面趋 ...
- SoC嵌入式软件架构设计之六:API设计方法
在嵌入式系统中,驱动都是以API的方式提供给应用进行调用.这里介绍嵌入式系统的API设计和管理方法. 驱动在系统中会按模块进行分类,比如按键驱动.LCD驱动.文件系统.card驱动.I2C驱动等等:每 ...