http://acm.hdu.edu.cn/game/entry/problem/list.php?chapterid=1§ionid=3
1.3.1 fatmouse 'trade # include <algorithm>/* Meaning: sort the value/price ratio. The purchase ratio is large. Sample input5 3 7 24 35 220 3 25 18 24 15 15 10-1-1 sample output13.333 31.500 */# include <stdio. h> # include <stdlib. h> const int maxn = 1010; struct node {double J, F; Double R;} A [maxn]; int CMP (const void * a, const void * B) {struct node * c = (node *) A; struct node * D = (node *) B; If (c-> r> D-> r) Return-1; else return 1 ;}int main () {int N; double m; double ans; while (scanf ("% lf % d", & M, & n )) {If (M =-1 & n =-1) break; For (INT I = 0; I <n; I ++) {scanf ("% lf", & A [I]. j, & A [I]. f); A [I]. R = (double) A [I]. j/A [I]. f;} qsort (A, N, sizeof (A [0]), CMP); ans = 0; For (INT I = 0; I <n; I ++) {If (M> = A [I]. f) {ans + = A [I]. j; m-= A [I]. f;} else {ans + = (a [I]. j/A [I]. f) * m; break;} printf ("%. 3lf \ n ", ANS);} return 0 ;}
1.3.2 this summer without AC * Sample input121 33 40 73 815 1915 2010 158 186 125 104 142 90 sample output5 */# include <stdio. h> # include <stdlib. h> # include <string. h> struct Ti {int S, e ;}; int compare (const void * a, const void * B); int main () {int I, N, K; struct Ti tis [101], temp [101]; while (scanf ("% d", & N )! = EOF) {If (n = 0) break; for (I = 0; I <n; I ++) {scanf ("% d ", & tis [I]. s, & tis [I]. e);} qsort (TIS, N, sizeof (TIS [0]), compare); k = 0; temp [k] = tis [0]; for (I = 1; I <n; I ++) {If (TIS [I]. s> = temp [K]. e) temp [++ K] = tis [I];} printf ("% d \ n", k + 1);} return 0 ;} int compare (const void * a, const void * B) {const struct Ti * P = (Ti *) A; const struct Ti * q = (Ti *) B; return p-> E-Q-> E ;}
1.3.3 ranking # include <string> # include <stdio. h >#include <algorithm> using namespace STD; # define n 1000int que [10]; struct node {char name [20]; int num; int score ;} STU [N]; bool CMP (const node & A, const node & B) {if (. score = B. score) {return strcmp (. name, B. name) <0? 1:0;} else {return. score> B. score ;}}/* Lexicographic Order of contact: n (0 <n <1st), m (0 <m <= 10), and a positive integer (positive integer) are displayed in row 1000) g; Sorting in rows 2nd gives a positive integer score from question 1st to question M. For N rows below, each row provides a candidate admission ticket number (a string of no more than 20 characters) the total number of questions solved by the student, and the question number of the M Question 4 5 2510 10 12 13 15cs004 3 5 1 3cs003 5 2 4 1 3 5cs002 2 1 2cs001 3 2 3 5 * /INT main () {int student, question, Judge, X, count; while (scanf ("% d", & student), student) {COUNT = 0; For (INT I = 1; I <= student; ++ I) {STU [I]. score = 0; STU [I]. num = 0;} scanf ("% d", & question, & judge); For (INT I = 1; I <= question; ++ I) {scanf ("% d", & que [I]) ;}for (INT I = 1; I <= student; ++ I) {scanf ("% S % d", & STU [I]. name, & STU [I]. num); While (STU [I]. num --) {scanf ("% d", & X); STU [I]. score + = que [X];} If (STU [I]. score> = judge) Count ++;} Sort (STU + 1, Stu + 1 + student, CMP); printf ("% d \ n", count ); for (INT I = 1; I <= student; ++ I) {If (STU [I]. score> = judge) printf ("% S % d \ n", STU [I]. name, STU [I]. score); elsebreak;} return 0 ;}
1.3.4 opening and closing personnel # include "stdafx. H "# include <iostream >#include <string> using namespace STD; struct node {string name, timee;} maxt, mint; // record the largest and smallest struct int main () {int t, n; string S, MIS, MAS; CIN> T; while (t --) {CIN> N; n --; CIN> S> mint. timee> maxt. timee; mint. name = maxt. name = s; while (n --) {CIN> S> MIS> MAS; If (MIS <mint. timee) {mint. name = s; mint. timee = MIS;} If (MAS> maxt. timee) {maxt. name = s; maxt. timee = mas ;}}cout <mint. name <"" <maxt. name <Endl;} return 0 ;}