ZOJ 1149 Dividing(穷举)
来源:互联网 发布:如何延长淘宝付款时间 编辑:程序博客网 时间:2024/06/10 11:29
Marsha and Bill own a collection of marbles. They want to split the collection among themselves so that both receive an equal share of the marbles. This would be easy if all the marbles had the same value, because then they could just split the collection in half. But unfortunately, some of the marbles are larger, or more beautiful than others. So, Marsha and Bill start by assigning a value, a natural number between one and six, to each marble. Now they want to divide the marbles so that each of them gets the same total value.
Unfortunately, they realize that it might be impossible to divide the marbles in this way (even if the total value of all marbles is even). For example, if there are one marble of value 1, one of value 3 and two of value 4, then they cannot be split into sets of equal value. So, they ask you to write a program that checks whether there is a fair partition of the marbles.
Input
Each line in the input describes one collection of marbles to be divided. The lines consist of six non-negative integers n1, n2, ..., n6, where ni is the number of marbles of value i. So, the example from above would be described by the input-line ``1 0 1 2 0 0''. The maximum total number of marbles will be 20000.
The last line of the input file will be ``0 0 0 0 0 0''; do not process this line.
Output
For each colletcion, output ``Collection #k:'', where k is the number of the test case, and then either ``Can be divided.'' or ``Can't be divided.''.
Output a blank line after each test case.
Sample Input
1 0 1 2 0 0
1 0 0 0 1 1
0 0 0 0 0 0
Sample Output
Collection #1:
Can't be divided.
Collection #2:
Can be divided.
Source: Mid-Central European Regional Contest 1999
思路:预处理输入的大理石的数目,然后枚举即可。
AC代码:
#include<stdio.h>int a[7];void enumerate(int sum) {int mid;int i1,i2,i3,i4,i5,i6;for(i1=0; i1<=a[1]; i1++)for(i2=0; i2<=a[2]; i2++)for(i3=0; i3<=a[3]; i3++)for(i4=0; i4<=a[4]; i4++)for(i5=0; i5<=a[5]; i5++)for(i6=0; i6<=a[6]; i6++){mid = 1*i1+2*i2+3*i3+4*i4+5*i5+6*i6;if(mid==sum/2) {printf("Can be divided.\n\n");return;}}printf("Can't be divided.\n\n");}int main(){int i;int iCase = 1;while(1){int sum = 0;for(i=1; i<=6; i++){scanf("%d",&a[i]);//数据预处理 if(a[i]!=0 && a[i]%6==0) a[i] = 6;else a[i] = a[i]%6;sum += a[i]*i;//预处理之后大理石的总价值}if (sum==0) break;printf("Collection #%d:\n",iCase++);if (sum%2==1) {printf("Can't be divided.\n\n");continue;}enumerate(sum);}return 0;}
- ZOJ 1149 Dividing(穷举)
- ZOJ 1149 Dividing
- zoj 1149 Dividing
- zoj 1149 Dividing
- ZOJ - 1149 Dividing
- dividing zoj 1149, PKU 1014
- poj 1014 || zoj 1149 Dividing
- zoj 1149 || poj 1014 Dividing(多重背包)
- Hdu 1059 Dividing & Zoj 1149 & poj 1014 Dividing(多重背包)
- zoj 1149 && hdu 1059 && poj 1014 Dividing
- poj 1014 && zoj 1149 Dividing --- dfs剪枝
- poj 1014 & zoj 1149 Dividing(多重背包+倍增思想优化)
- zoj 2705 Dividing a Chocolate
- [dp问题] Poj 1014 & Zoj 1149 (Dividing) 解题报告(转)
- TOJ 1081 ZOJ 1149 HDU 1059 Dividing / 多重背包二进制优化
- zoj 2705 Dividing a Chocolate 斐波那契数列应用 (8-B)
- Dividing ( 多重背包)
- POJ1014 Dividing(DP)
- 给大家一点福利吧,HTML做的天气预报。(转)
- 详解--康托展开
- Openstack常见问题解决------网络与服务
- print输出
- a[s++] = a[e]
- ZOJ 1149 Dividing(穷举)
- 51nod 1138 等差数列公式
- Web App、Hybrid App与Native App的区别
- 2017百度之星复赛 1003 Pokémon GO 递推
- Linux GPIO Manipulation via System File System, sysfs
- Window内存管理方式:页式 段式 段页式
- 阶乘中因子k的个数
- javaWeb:cookie和session
- hdu2896