【qduoj - 312】寻找唯一的萌妹(卡时)

题干:

寻找唯一的萌妹

Description

 

又到了一年一度ACMer暑期留校集训的日子了,目前一共有2n+1个小萌新报名参加暑期集训,其中2n个是帅哥,只有1个萌妹子,这是多么的悲催!由于暑期训练强度大,坚持下来可不是一件容易的事情,DHG学长想到了一个巧妙的方法,两个人组成一队,两人互相鼓励,互相监督,直到集训顺利完成。然而,只有具有相同抗压能力的两位同学才能组在一起,并且这个唯一的萌妹子比较高傲不愿意和现有的2n个帅哥组队,只想和下一个报名的同学组队。作为仍未报名的你,想和这传说中的萌妹子组队,要求你输出萌妹子的抗压能力值。

Input

 

第一行一个n(n<=1000000)

第二行2n+1个数,表示每个小萌新的抗压能力值xi(-99999999<xi<99999999)。

Output

 

只输出一个数字,表示萌妹的抗压能力值。

Sample Input 1 

2
1 2 2 1 3

Sample Output 1

3

Sample Input 2 

1
-2 -2 1

Sample Output 2

1

Hint

题目保证:有正确答案;

 

解题报告:

      这是集训队纳新的一道题目,比赛时是用map做的。超时了。

     其实用map也是可以的但是要用迭代器遍历或者mp[ a[i] ]这样遍历,而不能从-99999999~~+99999999这样遍历,这不是作死吗。

 

TLE代码:(1040ms)

#include<iostream>
#include<map>
#include<list>
#include<algorithm>
using namespace std;
list<int> lili;
bool cmp(const int & a,const int & b ) {return a<b;
}
map<int,int> mp;
int main()
{int n;int tmp;scanf("%d",&n);n=n*2+1;for(int i = 1; i<=n; i++) {scanf("%d",&tmp);if(mp[tmp]==1) {list<int> :: iterator it;for(it=lili.begin();it!=lili.end(); it++ ) {if(*it==tmp) break;}lili.erase(it);mp[tmp]=0;}else {mp[tmp]=1;lili.push_back(tmp);}}cout << lili.front() << endl;return 0; 
}

TLE代码2:(1272ms)

#include<iostream>
#include<map>
#include<list>
#include<algorithm>
using namespace std;
list<int> lili;
bool cmp(const int & a,const int & b ) {return a<b;
}
map<int,int> mp;
int main()
{int n;int tmp;scanf("%d",&n);n=n*2+1;for(int i = 1; i<=n; i++) {scanf("%d",&tmp);if(mp[tmp]==1) {mp.erase(tmp);}else {mp[tmp]=1;}}map<int,int> :: iterator it;for(it=mp.begin();it!=mp.end();it++) {printf("%d\n",*it);}return 0; 
}

wa代码:(1376ms)

#include<iostream>
#include<map>
using namespace std;
//int a[100000000];
map<int,int> mp;
int main()
{int n;int tmp;scanf("%d",&n);n=n*2+1;for(int i = 1; i<=n; i++) {scanf("%d",&tmp);mp[tmp]++;}for(int i = 1; i<=n; i++) {if(mp[i]&1) {printf("%d\n",i);break;}}return 0 ;
}
//2
//1 2 2 1 3

ac代码:

#include<iostream>
#include<algorithm>using namespace std;
int a[2000005];int main()
{int n;scanf("%d",&n);n=n*2+1;for(int i = 1; i<=n; i++) {scanf("%d",&a[i]);}sort(a+1,a+n+1); int cnt=1;int tmp=a[1];for(int i = 2; i<=n; i++) {if(tmp==a[i]) {cnt++;}else {if(cnt&1) {printf("%d",a[i-1]);return 0 ;}else {tmp=a[i];cnt=1;}}}printf("%d",a[n]);
//if(a[i]==a[i-1]) {
//			cnt++;
//			continue;
//		}
//		if( (cnt&1) ) {
//			printf("%d",a[i]); 
//			return 0;
//		}
//		cnt=1;
//	printf("$dddd");return 0 ;}

总结:

   1.首先注意数组别开小  开一个1e6肯定上来就玩完了直接RE告辞。得开2e6啊这题!

   2.容器这东西,,,很难说啊

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.mzph.cn/news/442035.shtml

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

python 遍历字典嵌套_Python 字典嵌套循环遍历

这是从接口获取到的json数据{* "code":"10000",* "charge":false,* "remain":0,* "msg":"查询成功",* "result":{* "status":0,* "msg":"ok",* "result":{* &…

ACMer的AC福音!手动扩栈外挂!(防止栈溢出)

还在因为 怕 g 提交时间很慢&#xff0c;但是用C 交又怕栈溢出&#xff1f;&#xff1f;&#xff1f; 我们都知道&#xff0c;如果代码里有 递归函数 频繁调用&#xff0c; 用 C 提交代码&#xff0c; 很可能就会 出现 Runtime Error (ACCESS_VIOLATION) 但是用G…

【HDU - 1452】 Happy 2004(因子和,逆元,快速幂)

题干&#xff1a; Happy 2004 Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) Total Submission(s): 1863 Accepted Submission(s): 1361 Problem Description Consider a positive integer X,and let S be the sum of all pos…

bootstrap-table 新增可编辑行_现代Web开发堆栈工具DevExtreme 新增Gantt组件,助力项目管理...

点击“了解更多”获取DevExpress DevExtreme v19.2正式版下载DevExtreme拥有高性能的HTML5 / JavaScript小部件集合&#xff0c;使您可以利用现代Web开发堆栈(包括React&#xff0c;Angular&#xff0c;ASP.NET Core&#xff0c;jQuery&#xff0c;Knockout等)构建交互式的Web应…

关抢占 自旋锁_互斥锁、自旋锁、读写锁、悲观锁、乐观锁的应用场景

前言生活中用到的锁&#xff0c;用途都比较简单粗暴&#xff0c;上锁基本是为了防止外人进来、电动车被偷等等。但生活中也不是没有 BUG 的&#xff0c;比如加锁的电动车在「广西 - 窃格瓦拉」面前&#xff0c;锁就是形同虚设&#xff0c;只要他愿意&#xff0c;他就可以轻轻松…

【HDU - 1852】 Beijing 2008()

题干&#xff1a; Beijing 2008 Time Limit: 1000/1000 MS (Java/Others) Memory Limit: 32768/65535 K (Java/Others) Total Submission(s): 917 Accepted Submission(s): 394 Problem Description As we all know, the next Olympic Games will be held in Beiji…

dvwa详解_DVWA(六):XSSReflected 反射型XSS全等级详解

XSS 概念&#xff1a;由于web应用程序对用户的输入过滤不严&#xff0c;通过html注入篡改网页&#xff0c;插入恶意脚本&#xff0c;从而在用户浏览网页时&#xff0c;控制用户浏览器的一种攻击。XSS类型&#xff1a;Reflected(反射型)&#xff1a;只是简单的把用户输入的数据反…

直线的端点画垂线的lisp_【以课说法】线段、射线、直线

课例概况课例点晴你的课堂是碎片化的知识教学&#xff0c;还是结构化的问题探究&#xff1f;如何把碎片化的知识教学变成结构化的问题探究&#xff1f;实施路径就是问题串&#xff0c;用问题串统整知识点&#xff1b;围绕问题串&#xff0c;从问题引发、问题探究&#xff0c;直…

*【CF#633B】 A Trivial Problem(二分或枚举)

题干&#xff1a; Mr. Santa asks all the great programmers of the world to solve a trivial problem. He gives them an integer m and asks for the number of positive integers n, such that the factorial of n ends with exactly m zeroes. Are you among those grea…

wordpress拒绝访问_Nginx + Wordpress页面或帖子URL返回拒绝访问

谢谢你的答案 r3wt。但是&#xff0c;我猜上面的配置文件是不合适的我不想保持原样(但是对于我来说开发似乎没问题&#xff0c;因为部署我宁愿为每个站点使用单独的配置文件)。所以&#xff0c;别名部分和我的问题应该正确定义try_files因为我想要捕获链接以localhost / szpetr…

【HDU - 2104】hide handkerchief (素数)

题干&#xff1a; The Children’s Day has passed for some days .Has you remembered something happened at your childhood? I remembered I often played a game called hide handkerchief with my friends. Now I introduce the game to you. Suppose there are N peo…

python高级编程装饰器_Python装饰器

def my_decorator(function):def _my_decorator(*args, **kw):#在调用实际函数之前做些填充工作res function(*args, **kw)#做完某些填充工作之后return res#返回子函数return _my_decorator当装饰器需要参数时&#xff0c;必须使用第二级封装。def my_decorator(arg1, arg2):…

【HihoCoder - 1269】 优化延迟 (优先队列+二分优化)

题干&#xff1a; 小Ho编写了一个处理数据包的程序。程序的输入是一个包含N个数据包的序列。每个数据包根据其重要程度不同&#xff0c;具有不同的"延迟惩罚值"。序列中的第i个数据包的"延迟惩罚值"是Pi。如果N个数据包按照<Pi1, Pi2, ... PiN>的顺…

带有风的诗词_带有风的诗句

带有风的诗句1、古道西风瘦马&#xff0c;夕阳西下&#xff0c;断肠人在天涯。——马致远《天净沙秋思》2、欲乘风归去&#xff0c;又恐琼楼玉宇。——苏轼《水调歌头明月几时有》3、道通天地有形外&#xff0c;思入风云变态中。——程颢《秋日》4、津亭杨柳碧毵毵&#xff0c;…

【ZOJ - 3210】A Stack or A Queue? (模拟)

题干&#xff1a; Do you know stack and queue? Theyre both important data structures. A stack is a "first in last out" (FILO) data structure and a queue is a "first in first out" (FIFO) one. Here comes the problem: given the order of …

ehchache验证缓存过期的api_Ehcache缓存配置

Cache的配置很灵活&#xff0c;官方提供的Cache配置方式有好几种。你可以通过声明配置、在xml中配置、在程序里配置或者调用构造方法时传入不同的参数。你可以将Cache的配置从代码中剥离出来&#xff0c;也可以在使用运行时配置&#xff0c;所谓的运行时配置无非也就是在代码中…

*【POJ - 3061】 Subsequence (尺取或二分)

题干&#xff1a; A sequence of N positive integers (10 < N < 100 000), each of them less than or equal 10000, and a positive integer S (S < 100 000 000) are given. Write a program to find the minimal length of the subsequence of consecutive eleme…

alert 回调_JavaScript中到底什么时候回调函数Callback

什么是回调函数Callback简单的理解&#xff1a;回调函数是在另一个函数执行完毕后执行的函数 - 因此名称为call back。复杂的理解&#xff1a;在JavaScript中&#xff0c;函数是对象。因此&#xff0c;函数可以将函数作为参数&#xff0c;并且可以由其他函数返回。执行此操作的…

【CF#148B】Escape(模拟)

题干&#xff1a; The princess is going to escape the dragons cave, and she needs to plan it carefully. The princess runs at vp miles per hour, and the dragon flies at vd miles per hour. The dragon will discover the escape after t hours and will chase the…

mysql sql语句分页查询_如何用sql语句 实现分页查询?

我制作了一个数据库其中一张表createtablenews(news_idintprimarykeyidentity(1,1),news_titlevarchar(50)notnull,news_authorvarchar(20),news_summaryvarchar(50),news_contenttext...我制作了一个数据库其中一张表create table news(news_id int primary key identity(1,1)…