HDOJ-1029(简单dp或者排序)
Ignatius and the Princess IV
hdoj-1029
- 这里主要是先排序,因为要找出现了一半以上的数字,所以出现的数字一定在中间
方法一:
#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<cmath>
using namespace std;
int n;
int a[10000007];
int main(){
while(scanf("%d",&n)!=EOF){
for(int i=0;i<n;i++){
scanf("%d",&a[i]);
}
sort(a,a+n);
cout<<a[n/2]<<endl;
}
//system("pause");
return 0;
}
方法二:简单计算出每个数字出现的次数
#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<cmath>
using namespace std;
int n;
int a[10000007];
int main(){
while(scanf("%d",&n)!=EOF){
for(int i=0;i<n;i++){
scanf("%d",&a[i]);
}
sort(a,a+n);
//cout<<a[n/2]<<endl;
int k=0;
for(int i=0;i<n-1;i++){
if(a[i]!=a[i+1]){
//cout<<k<<endl;
if(k+1>=(n+1)/2){
cout<<a[i]<<endl;
break;
}
k=0;
}else{
k++;
if(k+1>=(n+1)/2){
cout<<a[i]<<endl;
break;
}
}
}
}
//system("pause");
return 0;
}
HDOJ-1029(简单dp或者排序)的更多相关文章
- HDOJ/HDU 1029 Ignatius and the Princess IV(简单DP,排序)
此题无法用JavaAC,不相信的可以去HD1029题试下! Problem Description "OK, you are not too bad, em- But you can nev ...
- HDOJ 1501 Zipper 【简单DP】
HDOJ 1501 Zipper [简单DP] Problem Description Given three strings, you are to determine whether the th ...
- Codeforces Round #267 (Div. 2)D(DFS+单词hash+简单DP)
D. Fedor and Essay time limit per test 2 seconds memory limit per test 256 megabytes input standard ...
- 『简单dp测试题解』
这一次组织了一场\(dp\)的专项考试,出了好几道经典的简单\(dp\)套路题,特开一篇博客写一下题解. Tower(双向dp) Description 信大家都写过数字三角形问题,题目很简单求最大化 ...
- POJ1088:滑雪(简单dp)
题目链接: http://poj.org/problem?id=1088 题目要求: 一个人可以从某个点滑向上下左右相邻四个点之一,当且仅当高度减小.求可以滑落的最长长度. 题目解析: 首先要先排一 ...
- Kattis - bank 【简单DP】
Kattis - bank [简单DP] Description Oliver is a manager of a bank near KTH and wants to close soon. The ...
- URAL 1203 Scientific Conference 简单dp 难度:0
http://acm.timus.ru/problem.aspx?space=1&num=1203 按照结束时间为主,开始时间为辅排序,那么对于任意结束时间t,在此之前结束的任务都已经被处理, ...
- hdu1160简单dp最长下降子序列
/* 简单dp,要记录顺序 解:先排序,然后是一个最长下降子序列 ,中间需记录顺序 dp[i]=Max(dp[i],dp[j]+1); */ #include<stdio.h> #incl ...
- 4.15 每周作业 —— 简单DP
免费馅饼 Time Limit : 2000/1000ms (Java/Other) Memory Limit : 65536/32768K (Java/Other) Total Submissi ...
随机推荐
- python的re模块一些方法 && Tkinter图形界面设计 && 终止python运行函数 && python读写文件 && python一旦给字符串赋值就不能单独改变某个字符,除非重新给变量赋值
Tkinter图形界面设计见:https://www.cnblogs.com/pywjh/p/9527828.html#radiobutton 终止python运行函数: 采用sys.exit(0)正 ...
- CodeCraft-20 (Div. 2) B. String Modification (字符串,规律)
题意:有一个长度为\(n\)的字符串,你可以选取一个值\(k(1\le k \le n)\),然后遍历字符串,每次将区间长度为\(k\)的字符串反转,求反转后字典序最小的字符串,并输出\(k\)的值. ...
- 洛谷 P5837 [USACO19DEC]Milk Pumping G (单源最短路,dijkstra)
题意:有一\(n\)个点,\(m\)条边的双向图,每条边都有花费和流量,求从\(1\)~\(n\)的路径中,求\(max\frac{min(f)}{\sum c}\). 题解:对于c,一定是单源最短路 ...
- c#小灶——9.算术运算符
算数运算符用来在程序中进行运算. 首先,了解最简单的加(+)减(-)乘(*)除(/)运算符: 举例 int a = 1; int b = 2; int c = a + b; Console.Write ...
- spring再学习之注解
1.使用注解配置spring <?xml version="1.0" encoding="UTF-8"?> <beans xmlns:xsi= ...
- appveyor build failed --
在 https://www.cnblogs.com/lqerio/p/11117498.html 使用了appveyor 进行 hexo 博客的版本控制持续集成. 今天push 到 github的 r ...
- QXDM和QCAT软件使用指南
一.传送门 链接:https://pan.baidu.com/s/1i55YXnf 密码:v6nw 二.QXDM,QPST和QCAT的简单说明 QXDM,QPST和QCAT是Qualcomm高通公司针 ...
- 牛客网-Beauty of Trees 【加权并查集】
锟斤拷锟接o拷https://www.nowcoder.com/acm/contest/119/A锟斤拷源锟斤拷牛锟斤拷锟斤拷 锟斤拷目锟斤拷锟斤拷 It锟斤拷s universally acknow ...
- Netty(二)Netty 与 NIO 之前世今生
2.1 Java NIO 三件套 在 NIO 中有几个核心对象需要掌握:缓冲区(Buffer).选择器(Selector).通道(Channel). 2.1.1 缓冲区 Buffer 1.Buffer ...
- How to create a folder symbol link in macOS
How to create a folder symbol link in macOS macOS 创建文件夹链接 Make AliasMake Alias Symbolic Links 符号链接 $ ...