[kuangbin带你飞]专题十二 基础DP1 -B - Ignatius and the Princess IV

news/2024/11/28 5:28:06/

“OK, you are not too bad, em… But you can never pass the next test.” feng5166 says.

“I will tell you an odd number N, and then N integers. There will be a special integer among them, you have to tell me which integer is the special one after I tell you all the integers.” feng5166 says.

“But what is the characteristic of the special integer?” Ignatius asks.

“The integer will appear at least (N+1)/2 times. If you can’t find the right integer, I will kill the Princess, and you will be my dinner, too. Hahahaha…..” feng5166 says.

Can you find the special integer for Ignatius?


Input
The input contains several test cases. Each test case contains two lines. The first line consists of an odd integer N(1<=N<=999999) which indicate the number of the integers feng5166 will tell our hero. The second line contains the N integers. The input is terminated by the end of file.

Output
For each test case, you have to output only one line which contains the special number you have found.

Sample Input
5
1 3 2 3 3
11
1 1 1 1 1 5 5 5 5 5 5
7
1 1 1 1 1 1 1

Sample Output
3
5
1


我的这个做法比较奇特,一般来说都能过,利用了自定义的哈希函数,活生生把一道简单dp题变成一道智障题,哈哈哈,稍后再给出dp解法

#include"iostream"
#include"algorithm"
#include"string.h"
using namespace std;int ai[1000100];
int sign[1000100];
int main()
{int n;while(cin>>n){memset(sign,0,sizeof(sign));int res;for(int i=0;i<n;i++){cin>>ai[i];int a=ai[i]%999993;sign[a]++;if(sign[a]>=(n+1)/2){res=ai[i];}}cout<<res<<endl;}return 0;
}

http://www.ppmy.cn/news/126027.html

相关文章

Android P DP1:WiFi-RTT、刘海、多摄像头、GIF动画、NNAPI 1.1

\ 看新闻很累&#xff1f;看技术新闻更累&#xff1f;试试下载InfoQ手机客户端&#xff0c;每天上下班路上听新闻&#xff0c;有趣还有料&#xff01;\ \\ 谷歌发布了Android P第一个开发预览版&#xff08;DP1&#xff09;&#xff0c;其中有几项值得注意的新特性&#xff1a;…

[kuangbin带你飞]专题十二 基础DP1 H - Tickets HDU - 1260

题目描述 Jesus, what a great movie! Thousands of people are rushing to the cinema. However, this is really a tuff time for Joe who sells the film tickets. He is wandering when could he go back home as early as possible. A good approach, reducing the total …

[kuangbin带你飞]专题十二 基础DP1

ID Origin Title 题解连接 167 / 465 Problem A HDU 1024 Max Sum Plus Plus here 234 / 372 Problem B HDU 1029 Ignatius and the Princess IV 水题&#xff01;&#xff01;&#xff01; 161 / 259 Problem C HDU 1069 Monkey and Banana here …

R1286K010E(DP1/107)

R1286K010E,电源IC R1286K010E(DP1/107) 2ch DCDC(Step Up DC/DC and lnverting DC/DC) 2ch DCIDC转换器是专为AMOL ED显示电源而设计的。它包括 升压式直流变换器和逆变式DC/DC变换器。 输出电压&#xff1a;【4.6V到5.8V可调音圈】 操作电压&#xff1a;【2.3V至5.5V】 输出电…

遭遇krnln.fnr,com.run,shell.fne,dp1.fne,eAPI.fne,internet.fne,RegEx.fnr,spec.fne等

遭遇krnln.fnr,com.run,shell.fne,dp1.fne,eAPI.fne,internet.fne,RegEx.fnr,spec.fne等 一位网友说他的电脑可能中病毒了&#xff0c;症状为把U盘中的文件夹改名后再双击&#xff0c;就提示找不到文件夹。 通过&#xff31;&#xff31;远程协助&#xff0c;先检查U盘&#xf…

极客日报第 71 期:虎牙被抬员工当事人再发声;Android 12 DP1 带来新隐私功能;IBM 考虑出售 Watson Health 业务

文章目录 一、互联网快讯二、程序员专属三、Github 每日精选四、CSDN 社区优质博文精选 一、互联网快讯 1、茄子快传发现多个安全漏洞 安全公司趋势科技报告在茄子快传中发现多个安全漏洞&#xff0c;而它的漏洞能导致远程代码执行。茄子快传是下载量最高的传输应用&#xff…

Zut_round 8(多维dp1)

A: 这一题我开始的想法是&#xff1a;先找出两个字符串的最长公共子序列的长度&#xff0c;在用两个字符串中的较大值减它。但交了好几次一直wa&#xff0c;就换了一种思路 #include <bits/stdc.h> using namespace std; const int N 1005; char a[N],b[N]; int f[N][N…

RCE漏洞演示,墨者靶场

#案列演示 打开墨者靶场&#xff0c;黑盒#命令注入执行分析 这个功能点有这么个功能&#xff0c;进行类似的像我们电脑上ping命令&#xff0c;这相当于就满足了命令&#xff0c;明显可能出现命令执行漏洞&#xff0c;可控变量和漏洞函数都存在。第一要去分析是什么操作系统&am…