鍏堝皢box榪涜鎺掑簭銆?br />濡傛灉box閲岄潰鐨勬暟鐨勬渶澶у叕綰︽暟涓嶄負1鐨勮瘽錛岄偅涔堟墍鏈夌粍鎴愮殑鏁幫紝鍙彲鑳芥槸榪欎釜鍏害鏁扮殑鍊嶆暟錛屽洜姝ゆ病鏈変笂闄愶紝杈撳嚭涓?.
鐢╨ast璁板綍鏈灝忕殑鈥滀笉鑳界粍鎴愮殑鏁扳濄傝繖鏍峰綋last涔嬪悗鏈塨oxs[0]涓繛緇暟閮藉彲浠ョ粍鎴愮殑璇濓紝閭d箞鎵鏈夌殑鏁伴兘鍙互緇勬垚銆?br />last+1...last+box[0]鍙互緇勬垚鐨勮瘽錛岄偅涔堟瘡涓暟閮藉姞涓涓猙ox[0],閭d箞鏂頒竴杞殑box[0]涓暟涔熷彲浠ョ粍鎴愶紝浠ユ綾繪帹銆?br />
#include聽<iostream>
#include聽<fstream>
using聽namespace聽std;
ifstream聽fin("nuggets.in");
ofstream聽fout("nuggets.out");
#ifdef聽_DEBUG
#define聽out聽cout
#define聽in聽cin
#else
#define聽out聽fout
#define聽in聽fin
#endif
int聽box_num;
int聽boxs[10];
bool聽ok[256];
int聽gcd(int聽a,int聽b)
{
聽聽聽聽if(a<b)聽swap(a,b);
聽聽聽聽int聽tmp;
聽聽聽聽while(b!=0){
聽聽聽聽聽聽聽聽tmp聽=聽a;
聽聽聽聽聽聽聽聽a聽=聽b;
聽聽聽聽聽聽聽聽b聽=聽tmp%b;
聽聽聽聽}
聽聽聽聽return聽a;
}
void聽solve()
{
聽聽聽聽in>>box_num;
聽聽聽聽for(int聽i=0;i<box_num;++i)
聽聽聽聽聽聽聽聽in>>boxs[i];
聽聽聽聽sort(&boxs[0],&boxs[box_num]);
聽聽聽聽
聽聽聽聽int聽t聽=聽boxs[0];
聽聽聽聽for(int聽i=1;i<box_num;++i){
聽聽聽聽聽聽聽聽t聽=聽gcd(t,boxs[i]);
聽聽聽聽}
聽聽聽聽if(t!=1){
聽聽聽聽聽聽聽聽out<<0<<endl;
聽聽聽聽聽聽聽聽return;
聽聽聽聽}
聽聽聽聽memset(ok,0,sizeof(ok));
聽聽聽聽int聽last聽=聽0;
聽聽聽聽ok[0]聽=聽true;
聽聽聽聽int聽i=0;
聽聽聽聽while(true){
聽聽聽聽聽聽聽聽if(ok[i%256]){
聽聽聽聽聽聽聽聽聽聽聽聽ok[i%256]聽=聽0;
聽聽聽聽聽聽聽聽聽聽聽聽if(i-last>=boxs[0]){
聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽out<<last<<endl;
聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽return;
聽聽聽聽聽聽聽聽聽聽聽聽}
聽聽聽聽聽聽聽聽聽聽聽聽for(int聽x=0;x<box_num;++x){
聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽ok[(i+boxs[x])%256]聽=聽true;
聽聽聽聽聽聽聽聽聽聽聽聽}
聽聽聽聽聽聽聽聽}else{
聽聽聽聽聽聽聽聽聽聽聽聽last聽=聽i;
聽聽聽聽聽聽聽聽}
聽聽聽聽聽聽聽聽++i;
聽聽聽聽}
}
int聽main(int聽argc,char聽*argv[])
{
聽聽聽聽solve();聽
聽聽聽聽return聽0;
}
Beef McNuggets
Hubert Chen Farmer Brown's cows are up in arms, having heard that McDonalds is
considering the introduction of a new product: Beef McNuggets. The
cows are trying to find any possible way to put such a product in a
negative light.
One strategy the cows are pursuing is that of `inferior packaging'.
``Look,'' say the cows, ``if you have Beef McNuggets in boxes of 3, 6,
and 10, you can not satisfy a customer who wants 1, 2, 4, 5, 7, 8, 11,
14, or 17 McNuggets. Bad packaging: bad product.''
Help the cows. Given N (the number of packaging options, 1 <= N
<= 10), and a set of N positive integers (1 <= i <= 256) that
represent the number of nuggets in the various packages, output the
largest number of nuggets that can not be purchased by buying nuggets
in the given sizes. Print 0 if all possible purchases can be made or
if there is no bound to the largest number.
The largest impossible number (if it exists) will be no larger than
2,000,000,000.
PROGRAM NAME: nuggets
INPUT FORMAT
Line 1: | N, the number of packaging options |
Line 2..N+1: | The number of nuggets in one kind of
box |
SAMPLE INPUT (file nuggets.in)
3
3
6
10
OUTPUT FORMAT
The output file should contain a single line containing a single integer
that represents the largest number of nuggets that can not be represented
or 0 if all possible purchases can be made or if there is no bound to
the largest number.
SAMPLE OUTPUT (file nuggets.out)
17

]]>