首页 > ACM题库 > HDU-杭电 > hdu 2378 Cutting Banknotes[解题报告]hoj
2014
01-05

hdu 2378 Cutting Banknotes[解题报告]hoj

Cutting Banknotes

问题描述 :

Philip is often faced with a big problem: after going out for dinner or having a few beers, he owes money to his friends or the other way around. These are often small amounts, but because Philip hates coins, his wallet contains only banknotes. Therefore he usually can’t pay the amount exactly. Since he hates coins, he also doesn’t allow his friends to return them as change. He does allow for banknotes as change though.

To accomodate for this problem, he and his friends came up with the following idea: let’s pay with pieces of banknotes. To make the cutting easy, they only cut banknotes in two equally-sized pieces, cut those pieces in two pieces, and so on. This yields a much larger range of amounts that can be paid. Philip wonders which ones exactly.

输入:

On the first line an integer t (1 <= t <= 100): the number of test cases. Then for each test case:

One line with a number x (0.01 <= x <= 10 000.00): the amount Philip has to pay.

This is formatted with two decimal digits and a period as decimal separator.

One line with a positive integer n (1 <= n <= 1 000): the number of different banknotes.

n lines, each with an integer bi (1 <= bi <= 10 000): the values of the banknotes.

输出:

On the first line an integer t (1 <= t <= 100): the number of test cases. Then for each test case:

One line with a number x (0.01 <= x <= 10 000.00): the amount Philip has to pay.

This is formatted with two decimal digits and a period as decimal separator.

One line with a positive integer n (1 <= n <= 1 000): the number of different banknotes.

n lines, each with an integer bi (1 <= bi <= 10 000): the values of the banknotes.

样例输入:

4
10.75
3
2
10
20
0.33
1
1
10000.00
1
2500
1.00
2
3
5

样例输出:

yes
no
yes
yes

#include <iostream>
#include <cstdio>
using namespace std;
const double eps = 1e-7;
	
int cases, m, c, gg;
double des, xs;
bool flag;
int gcd(int a, int b) {
	if (b == 0) return a; else return gcd(b, a%b);
}
double abs(double x) {
	if (x < 0) return -x; else return x;
}
int main() {
 scanf("%d", &cases);
 while (cases--) {
 scanf("%lf", &des);
 des = 4*des;
 xs = des-int(des);
 flag = true;if (abs(xs)>eps) flag = false;
 scanf("%d", &m);
 for (int i = 0; i < m; i++) {
 scanf("%d", &c);
 if (!i) gg = c; else gg = gcd(c, gg);
 }
 while ((gg&1)==0) gg>>=1;
 if (int(des)%gg!=0) flag = false;
		if (flag) puts("yes"); else puts("no");
 }
 return 0;
}

  1. 您没有考虑 树的根节点是负数的情况, 若树的根节点是个很大的负数,那么就要考虑过不过另外一边子树了

  2. 第2题,TCP不支持多播,多播和广播仅应用于UDP。所以B选项是不对的。第2题,TCP不支持多播,多播和广播仅应用于UDP。所以B选项是不对的。