HDU 1718 Rank counting sort解法
本题是利用counting sort的思想去解题。
注意本题,好像利用直接排序,然后查找rank是会直接被判WA的。奇怪的推断系统。
由于分数值的范围是0到100,很小,而student 号码又很大,故此天然的须要利用counting sort的情况。
#include <stdio.h>
#include <string.h> const int MAX_N = 101;
int arr[MAX_N]; int main()
{
int Jackson, JackScore, stu, score;
while (scanf("%d", &Jackson) != EOF)
{
memset(arr, 0, sizeof(int)*MAX_N);
while (scanf("%d %d", &stu, &score) && stu)
{
if (stu == Jackson) JackScore = score;
arr[score]++;
}
int rank = 1;
for (int i = 100; i >= 0; i--)
{
if (i == JackScore)
{
printf("%d\n", rank);
break;
}
rank += arr[i];
}
}
return 0;
}
HDU 1718 Rank counting sort解法的更多相关文章
- hdu 1718 Rank
题目连接 http://acm.hdu.edu.cn/showproblem.php?pid=1718 Rank Description Jackson wants to know his rank ...
- HDOJ(HDU) 1718 Rank(水题、、、)
Problem Description Jackson wants to know his rank in the class. The professor has posted a list of ...
- HDU 1718 Rank (排序)
题意:给你n个学号和成绩,并且给定一个学号,让找这个学号是多少名. 析:用个结构体,按成绩排序,然后找那个学号,这个题有一个小坑,那就是并列的情况, 可能并列多少名,这个要考虑一下,其他的easy! ...
- HDU 1718 Rank 排序
解题报告:给一个班的学生的分数排序,然后判断Jack在他们班级的排名是多少,并且有如下规定,若多个人的分数相同,则他们的排名也 是相同的.说白了就是问这个班上分数比Jack高的人数有多少个,如果有n个 ...
- find out the neighbouring max D_value by counting sort in stack
#include <stdio.h> #include <malloc.h> #define MAX_STACK 10 ; // define the node of stac ...
- ACM: hdu 1811 Rank of Tetris - 拓扑排序-并查集-离线
hdu 1811 Rank of Tetris Time Limit:1000MS Memory Limit:32768KB 64bit IO Format:%I64d & % ...
- counting sort 计数排序
//counting sort 计数排序 //参考算法导论8.2节 #include<cstdio> #include<cstring> #include<algorit ...
- 41. First Missing Positive(困难, 用到 counting sort 方法)
Given an unsorted integer array, find the first missing positive integer. For example, Given [1,2,0] ...
- 《算法导论》——计数排序Counting Sort
今天贴出的算法是计数排序Counting Sort.在经过一番挣扎之前,我很纠结,今天这个算法在一些scenarios,并不是最优的算法.最坏情况和最好情况下,时间复杂度差距很大. 代码Countin ...
随机推荐
- Debug 和 Release 编译方式的本质区别
一.Debug 和 Release 编译方式的本质区别 Debug 通常称为调试版本,它包含调试信息,并且不作任何优化,便于程序员调试程序.Release 称为发布版本,它往往是进行了各种优化,使得程 ...
- poj3592Instantaneous Transference(tarjan+spfa)
http://poj.org/problem?id=3592提交了30多次了 受不了了 两份的代码基本上一样了 一个AC一个WA 木办法 贴份别人的吧 改得跟我得一样 人家能A 我是WA.. 强连通 ...
- poj 1442 Black Box(堆 优先队列)
题目:http://poj.org/problem?id=1442 题意:n,m,分别是a数组,u数组的个数,u[i]w为几,就加到a几,然后输出第i 小的 刚开始用了一个小顶堆,超时,后来看了看别人 ...
- poj 3253 Fence Repair (哈夫曼树 优先队列)
题目:http://poj.org/problem?id=3253 没用long long wrong 了一次 #include <iostream> #include<cstdio ...
- javascript 一些需要知道的东西
这里我直接贴出代码,注释已经补全,欢迎指正: <script type="text/javascript"> /** 1,js中一切皆是对象,函数也是, 2,当定义变量 ...
- 《C#并行编程高级教程》第9章 异步编程模型 笔记
这个章节我个人感觉意义不大,使用现有的APM(异步编程模型)和EAP(基于时间的异步模型)就很够用了,针对WPF和WinForm其实还有一些专门用于UI更新的类. 但是出于完整性,还是将一下怎么使用. ...
- java日历类Calendar简单使用
import java.util.Calendar; import java.util.TimeZone; public class Test1 { public static void main(S ...
- Asp.Net 高性能框架 SqlSugar.ORM 2.3
一.前言 SqlSugar从去年到现在已经一年了,版本从1.0升到了现在的2.3 ,这是一个稳定版本 ,有数家公司已经项目上线,在这里我将SqlSugar的功能重新整理成一篇新的贴子,希望大家喜欢. ...
- HDU 3711 Binary Number
Binary Number Time Limit: 4000/2000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others)Tot ...
- HDU 5628 Clarke and math Dirichlet卷积+快速幂
题意:bc round 72 中文题面 分析(官方题解): 如果学过Dirichlet卷积的话知道这玩意就是g(n)=(f*1^k)(n), 由于有结合律,所以我们快速幂一下1^k就行了. 当然,强行 ...