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解法

时间: 2024-07-31 14:04:38

HDU 1718 Rank counting sort解法的相关文章

Hdu 1718 Rank

Rank Time Limit: 1000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 5525    Accepted Submission(s): 2201 Problem Description Jackson wants to know his rank in the class. The professor has posted a list of stud

HDU 1718 Rank (排序)

题意:给你n个学号和成绩,并且给定一个学号,让找这个学号是多少名. 析:用个结构体,按成绩排序,然后找那个学号,这个题有一个小坑,那就是并列的情况, 可能并列多少名,这个要考虑一下,其他的easy! 代码如下: #include <iostream> #include <cstdio> #include <algorithm> #include <queue> #include <vector> #include <cstring>

hdu 3518 Boring counting(后缀数组)

Boring counting                                                                       Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) Problem Description 035 now faced a tough problem,his english teacher gives him

counting sort 计数排序

//counting sort 计数排序 //参考算法导论8.2节 #include<cstdio> #include<cstring> #include<algorithm> #include<cassert> using namespace std; const int k=5; const int n=7; int a[n]={5, 5, 1, 2 , 5, 4, 1}; int b[n]; int c[k+1]; int main() { int m

【HackerRank】 The Full Counting Sort

In this challenge you need to print the data that accompanies each integer in a list. In addition, if two strings have the same integers, you need to print the strings in their original order. Hence, your sorting algorithm should be stable, i.e. the

hdu 1704 Rank(floyd传递闭包)

题目链接:hdu 1704 Rank 题意: 有n个人,m场比赛,a与b打,每场都是awin,问不能确定其中两个人的win情况数. 题解: floyd传递闭包,这里我用bitset优化了一下. 1 #include<bits/stdc++.h> 2 #define F(i,a,b) for(int i=a;i<=b;++i) 3 using namespace std; 4 bitset<501>a[501]; 5 6 int n,m,t; 7 8 int main(){ 9

HDU 1754 树状数组 解法

mnesia在频繁操作数据的过程可能会报错:** WARNING ** Mnesia is overloaded: {dump_log, write_threshold},可以看出,mnesia应该是过载了.这个警告在mnesia dump操作会发生这个问题,表类型为disc_only_copies .disc_copies都可能会发生. 如何重现这个问题,例子的场景是多个进程同时在不断地mnesia:dirty_write/2 mnesia过载分析 1.抛出警告是在mnesia 增加dump

find out the neighbouring max D_value by counting sort in stack

1 #include <stdio.h> 2 #include <malloc.h> 3 #define MAX_STACK 10 4 5 int COUNT = 0; 6 // define the node of stack 7 typedef struct node { 8 int data; 9 node *next; 10 }*Snode; 11 12 // define the stack 13 typedef struct Stack{ 14 Snode top; 1

Hdu 5439 Aggregated Counting (2015长春网络赛 ACM/ICPC Asia Regional Changchun Online 找规律)

题目链接: Hdu 5439 Aggregated Counting 题目描述: 刚开始给一个1,序列a是由a[i]个i组成,最后1就变成了1,2,2,3,3,4,4,4,5,5,5.......,最后问a[i]==n(i最大)时候,i最后一次出现的下标是多少? 解题思路: 问题可以转化为求a[i] == n (i最大),数列前i项的和为多少. index: 1 2 3 4 5 6 7 8 9 10 a:        1 2 2 3 3 4 4 4 5 5 可以观察出:ans[1] = 1,