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 ...
随机推荐
- Java面试题-并发工具
1. 如何实现一个流控程序,用于控制请求的调用次数?
- hdu4635Strongly connected
http://acm.hdu.edu.cn/showproblem.php?pid=4635 tarjan缩点 统计缩点后每个结点的出度入度 将那个包含原来点数最少的 且出度或者入度为0的大节点看作一 ...
- poj 1080 Human Gene Functions(dp)
题目:http://poj.org/problem?id=1080 题意:比较两个基因序列,测定它们的相似度,将两个基因排成直线,如果需要的话插入空格,使基因的长度相等,然后根据那个表格计算出相似度. ...
- HTML.ActionLink 和Html.Action和 Url.Action 的区别
1. html.ActionLink生成一个<a href=".."></a>标记..例如:@Html.ActionLink(“链接文本”.“someact ...
- [转] python程序的调试方法
qi09 原文 python程序的调试方法 本文讨论在没有方便的IDE工具可用的情况下,使用pdb调试python程序 源码例子 例如,有模拟税收计算的程序: #!/usr/bin/python de ...
- create a C# context menu from code
I try the one of your approach, it works well in my computer. Below is my code: public void AddConte ...
- Uva 796 Critical Links 找桥
这个题很简单,但是输入有毒,用字符串的我一直RE 然后换成这样瞬间AC #include <stdio.h> #include <string.h> #include < ...
- Selenium2Library中的Get Alert Message
今天在处理页面的弹出框(alert)时,发现Get Alert Message 并不如字面意思这么简单 函数说明如下: 很明了:(1)返回alert 的text (2)如果没有alert,则该keyw ...
- 环境监测小助手V1.1的Windows版
环境监测小助手V1.1——可以实时查看空气质量和城市排名 一款跨平台空气质量监测软件 数据来源互联网,请联网使用. 暂不支持效果预览. 下载地址:http://files.cnblogs.com/py ...
- 【译】 AWK教程指南 5AWK中的数组
awk程序中允许使用字符串当做数组的下标(index).利用这个特色十分有助于资料统计工作.(使用字符串当下标的数组称为Associative Array) 首先建立一个数据文件,并取名为 reg.d ...