PATULJCI Submit: 1156 Accepted:704 Time Limit: 1000MS Memory Limit: 65535K Description
Every day, while the dwarves are busy in the mines, Snow White prepares dinner for them; seven chairs, seven plates, seven forks and seven knives for seven hungry dwarves. One day nine dwarves came from the mines instead of seven (nobody knows how or why), each of them claiming to be one of Snow White's seven dwarves. Luckily, each dwarf wears a hat with a positive integer less than 100 written on it. Snow White, a famous mathematician, realised long ago that the sum of numbers on the hats of her seven dwarves was exactly 100. Write a program which determines which dwarves are legit, i.e. pick seven of nine numbers that add to 100.
InputThere are 9 lines of input. Each contains an integer between 1 and 99 (inclusive). All of the numbers will be distinct. Note: The test data will be such that the solution is unique.
OutputYour program must produce exactly seven lines of output – the numbers on the hats of Snow White's seven dwarves. Output the numbers in any order.
Sample Input 78
10
13
15
19
20
23
25
Sample Output 7
8
10
13
19
20
23
Source Croatian Open Competition in Informatics七个小矮人突然变成九个小矮人了,但真正的七个小矮人头上的编号加起来刚好是100,计算出哪些是真正的小矮人。方法很简单,先算出9个数之和,减100,则为多出来那两个数的和,然后计算是哪两个数之和。
模拟题
#include <stdio.h> main() { char time[6]; int N, num, ht, mt, money = 0; scanf("%d", &N); while (N--) { scanf("%s", time); ht = (time[0] - 48) * 10 + time[1] - 48; mt = (time[3] - 48) * 10 + time[4] - 48; scanf("%d", &num); if (ht >= 7 && ht < 19) { if ((ht + (mt + num)/60) == 19) money += ((mt + num)%60*5 + (60-mt)*10); else money += (num * 10); } else { if ((ht + (mt + num)/60) == 7) money += (((mt + num)%60)*10 + (60 - mt)*5); else money += (num * 5); } } printf("%d\n", money); // system("pause"); return 0; }
这是一道经典的数学问题,讲述了如何从九个不同的正整数中找出七个数,使其总和等于100。题目背景设定在一个有趣的童话故事中,通过数学的方式帮助Snow White辨别出真正的七个小矮人。
9550

被折叠的 条评论
为什么被折叠?



