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或者排序)的更多相关文章

  1. HDOJ/HDU 1029 Ignatius and the Princess IV(简单DP,排序)

    此题无法用JavaAC,不相信的可以去HD1029题试下! Problem Description "OK, you are not too bad, em- But you can nev ...

  2. HDOJ 1501 Zipper 【简单DP】

    HDOJ 1501 Zipper [简单DP] Problem Description Given three strings, you are to determine whether the th ...

  3. 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 ...

  4. 『简单dp测试题解』

    这一次组织了一场\(dp\)的专项考试,出了好几道经典的简单\(dp\)套路题,特开一篇博客写一下题解. Tower(双向dp) Description 信大家都写过数字三角形问题,题目很简单求最大化 ...

  5. POJ1088:滑雪(简单dp)

    题目链接:  http://poj.org/problem?id=1088 题目要求: 一个人可以从某个点滑向上下左右相邻四个点之一,当且仅当高度减小.求可以滑落的最长长度. 题目解析: 首先要先排一 ...

  6. Kattis - bank 【简单DP】

    Kattis - bank [简单DP] Description Oliver is a manager of a bank near KTH and wants to close soon. The ...

  7. URAL 1203 Scientific Conference 简单dp 难度:0

    http://acm.timus.ru/problem.aspx?space=1&num=1203 按照结束时间为主,开始时间为辅排序,那么对于任意结束时间t,在此之前结束的任务都已经被处理, ...

  8. hdu1160简单dp最长下降子序列

    /* 简单dp,要记录顺序 解:先排序,然后是一个最长下降子序列 ,中间需记录顺序 dp[i]=Max(dp[i],dp[j]+1); */ #include<stdio.h> #incl ...

  9. 4.15 每周作业 —— 简单DP

    免费馅饼 Time Limit : 2000/1000ms (Java/Other)   Memory Limit : 65536/32768K (Java/Other) Total Submissi ...

随机推荐

  1. CF1462-E2. Close Tuples (hard version)

    本题为hard版,还有一个easy版,区别在于k和m的取值不同. 题意: 给出一个由n个数字组成的数组 \(a\).现在定义一种子集为\(\{A_1, A_2, A_3, ..., A_m\}\),使 ...

  2. OpenStack Train版-8.安装neutron网络服务(控制节点)

    安装neutron网络服务(controller控制节点192.168.0.10) 创建neutron数据库 mysql -uroot CREATE DATABASE neutron; GRANT A ...

  3. KEIL + STM32 续

    接上一篇,debug出现问题 1.手动安装STM32 芯片包   Keil.STM32F1xx_DFP.2.2.0.pack; https://www.keil.com/dd2/Pack/ 百度网盘  ...

  4. P类问题,NP,NPC,HPHard,coNP,NPI问题 的简单认识

    参考<算法设计技巧与分析>--沙特 问题可以分为判定类问题和最优化问题,判定类问题可以转化为最优化问题,所以下面讨论的是判定类的问题. P类问题是可以在多项式时间  采用确定性算法给出解 ...

  5. test markdown && 代码高亮

    #include<cstdio> #include<cstring> #include<queue> #include<vector> #include ...

  6. codeforces 1059C. Sequence Transformation【构造】

    题目:戳这里 题意:有1,2,3...n这n个数,求一次这些数的gcd,删去一个数,直到剩下一个数为止.输出这n个gcd的最大字典序. 解题思路:一开始的gcd肯定是1,要让字典序最大,我们可以想到下 ...

  7. Gym102361A Angle Beats(直角三角形 计算几何)题解

    题意: \(n\)个点,\(q\)个询问,每次问包含询问点的直角三角形有几个 思路: 代码: #include<bits/stdc++.h> using namespace std; co ...

  8. 在利用手背扫描图像+K因子 对室内温度进行回归预测时碰到的问题

    1. 关于多输入流: 由于本Mission是双输入, 导师要求尽量能使用Inception之诸, 于是输入便成了问题. 思考: 在Github上找到了keras-inceptionV4进行对网络头尾的 ...

  9. ESLint & vue

    ESLint & vue { "name": "app", "version": "1.0.1", " ...

  10. Swift 5.3 All In One

    Swift 5.3 All In One refs xgqfrms 2012-2020 www.cnblogs.com 发布文章使用:只允许注册用户才可以访问!