# The Balance

Time Limit: 1000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total Submission(s): 4737    Accepted Submission(s): 1895

Problem Description

Now you are asked to measure a dose of medicine with a balance and a number of weights. Certainly it is not always achievable. So you should find out the qualities which cannot be measured from the range [1,S]. S is the total quality of all the weights.

Input

The input consists of multiple test cases, and each case begins with a single positive integer N (1<=N<=100) on a line by itself indicating the number of weights you have. Followed by N integers Ai (1<=i<=N), indicating the quality of each weight where 1<=Ai<=100.

Output

For each input set, you should first print a line specifying the number of qualities which cannot be measured. Then print another line which consists all the irrealizable qualities if the number is not zero.

Sample Input

3

1 2 4

3

9 2 1

Sample Output

0

2

4 5

``` 1 #include<iostream>
2 #include<vector>
3 #include<cstring>
4 #define maxn 20003
5 #define gong 10000
6 using namespace std;
7 int c1[maxn],c2[maxn];
8 int save[maxn];
9 int main()
10 {
11     int n,i,sum,j,k,count;
12     while(cin>>n)
13     {
14        vector<int>arr(n);
15        memset(c1,0,sizeof(c1));
16        memset(c2,0,sizeof c2);
17        memset(save,0,sizeof save);
18        count=sum=0;
19        for(i=0;i<n;i++)
20        {
21            cin>>arr[i];
22            sum+=arr[i];
23        }
24        for(i=-arr;i<=arr;i+=arr)
25        {
26            c1[i+gong]=1;
27        }
28      for(i=1;i<n;i++)
29      {
30          for(j=-sum;j<=sum;j++)
31          {
32            for(k=-arr[i];k<=arr[i]&&k+j<=sum;k+=arr[i])
33            {
34              c2[k+j+gong]+=c1[j+gong];
35            }
36          }
37
38          for(j=-sum+gong;j<=sum+gong;j++)
39          {
40              c1[j]=c2[j];
41              c2[j]=0;
42          }
43      }
44        int ans=0;
45        for(j=0;j<=sum;j++)
46        {
47            if(c1[j+gong]==0||c1[gong-j]==0)
48            {
49                save[ans++]=j;
50            }
51        }
52        cout<<ans<<endl;
53        if(ans)
54        {
55          for(i=0;i<ans;i++)
56          {
57              if(i==0)
58                  cout<<save[i];
59              else
60                  cout<<" "<<save[i];
61          }
62           cout<<endl;
63        }
64     }
65     return 0;
66 }```

657 篇文章64 人订阅

0 条评论

## 相关文章

### HDUOJ---Can you solve this equation?

Can you solve this equation? Time Limit: 2000/1000 MS (Java/Others)    Memory Li...

28880

### HDUOJ1060Leftmost Digit

Leftmost Digit Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/327...

32880

### HDUOJ----1170Milk

Milk Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java...

281100

### HDUOJ---3371Connect the Cities

Connect the Cities Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768...

33270

### hdu 3948 Portal (kusral+离线)

Portal Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Ja...

29960

### hdu 4405Aeroplane chess(概率DP)

Aeroplane chess Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32...

32650

### HDU-1011 Starship Troopers（树形dp）

Starship Troopers Time Limit: 10000/5000 MS (Java/Others) Memory Limit: 65536...

35370

### HDU 2147 kiki's game(规律，博弈)

kiki's game Time Limit: 5000/1000 MS (Java/Others)    Memory Limit: 40000/10000 ...

28660

### hdu----(5056)Boring count(贪心)

Boring count Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768...

33750

### HDUOJ---kiki's game

kiki's game Time Limit: 5000/1000 MS (Java/Others)    Memory Limit: 40000/1000 K...

32980 