注册 登录  
 加关注
   显示下一条  |  关闭
温馨提示!由于新浪微博认证机制调整,您的新浪微博帐号绑定已过期,请重新绑定!立即重新绑定新浪微博》  |  关闭

TOTO

Think and Be Different

 
 
 

日志

 
 

Dividing up(做了一下,但是还是通不过,郁闷)  

2006-11-30 22:20:27|  分类: 默认分类 |  标签: |举报 |字号 订阅

  下载LOFTER 我的照片书  |
Dividing up

Time limit: 3sec. Submitted: 23
Memory limit: 32M Accepted: 9
Source : ACM ICPC Mid-Central European 1999

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.      
 
code

#include <stdio.h>
#define  MAX 2000

unsigned int store[MAX][6];
bool is_odd(unsigned int num)
{
 return ((num % 2) == 1);
}
int main()
{
 unsigned int array[6];
 bool flag = true;
 unsigned int linenum =0;
 unsigned int j = 0;
 unsigned int t = 0;
 while(flag)
 {
 // for(int i = 0; i < 6; ++i)
  scanf("%d %d %d %d %d %d", array, array+1, array+2, array+3, array+4, array+5);
  flag = false;
  for(int i = 0; i < 6; ++i)
   flag = flag || (array[i] != 0);
  if(flag)
  {
   for(int i = 0; i < 6; ++i)
    store[linenum][i] = array[i];
   ++linenum;
  }
 }
 while(j < linenum)
 {
  for(int i = 0; i < 4; ++i)
  {
   t = i + 2;
   while((i + t) < 6)
   {
    if(is_odd(store[j][i]) && is_odd(store[j][t]))
    {
     if(is_odd(store[j][i+t+1]) && !is_odd(store[j][(i+t)/2]))
     {
      --store[j][i];
      --store[j][t];
      ++store[j][i+t+1];
     }
     if(!is_odd(store[j][i+t+1]) && !((store[j][(i+t)/2]+2) % 4))
     {
      --store[j][i];
      --store[j][t];
      store[j][(i+t)/2] += 2;
     }
    }
    t += 2;
   }
  }
  flag = false;
  for(int i = 0; i < 6; ++i)
  {
   flag = flag || (store[j][i] % 2);
  }
  printf("Collection #%d: n", ++j);
  if(!flag)
   printf("Can be divided. n");
  else
   printf("Can't be divided. n");
 }
}

  评论这张
 
阅读(339)| 评论(0)
推荐 转载

历史上的今天

评论

<#--最新日志,群博日志--> <#--推荐日志--> <#--引用记录--> <#--博主推荐--> <#--随机阅读--> <#--首页推荐--> <#--历史上的今天--> <#--被推荐日志--> <#--上一篇,下一篇--> <#-- 热度 --> <#-- 网易新闻广告 --> <#--右边模块结构--> <#--评论模块结构--> <#--引用模块结构--> <#--博主发起的投票-->
 
 
 
 
 
 
 
 
 
 
 
 
 
 

页脚

网易公司版权所有 ©1997-2017