zoukankan      html  css  js  c++  java
  • poj 1014 Dividing

    题目链接:http://poj.org/problem?id=1014

    解题思路:简单dp

     1 ///////////////////////////////////////////////////////////////////////////
     2 //problem_id: poj 1014
     3 //user_id: SCNU20102200088
     4 ///////////////////////////////////////////////////////////////////////////
     5 
     6 #include <algorithm>
     7 #include <iostream>
     8 #include <iterator>
     9 #include <iomanip>
    10 #include <cstring>
    11 #include <cstdlib>
    12 #include <string>
    13 #include <vector>
    14 #include <cstdio>
    15 #include <cctype>
    16 #include <cmath>
    17 #include <queue>
    18 #include <stack>
    19 #include <list>
    20 #include <set>
    21 #include <map>
    22 using namespace std;
    23 
    24 ///////////////////////////////////////////////////////////////////////////
    25 typedef long long LL;
    26 const double PI=acos(-1.0);
    27 
    28 const int x4[]={-1,0,1,0};
    29 const int y4[]={0,1,0,-1};
    30 const int x8[]={-1,-1,0,1,1,1,0,-1};
    31 const int y8[]={0,1,1,1,0,-1,-1,-1};
    32 
    33 typedef int T;
    34 T max(T a,T b){ return a>b? a:b; }
    35 T min(T a,T b){ return a<b? a:b; }
    36 ///////////////////////////////////////////////////////////////////////////
    37 
    38 ///////////////////////////////////////////////////////////////////////////
    39 //Add Code:
    40 ///////////////////////////////////////////////////////////////////////////
    41 
    42 int main(){
    43     ///////////////////////////////////////////////////////////////////////
    44     //Add code:
    45     int i,j,k,Case=1,n[10];
    46     while(scanf("%d",&n[1])!=EOF){
    47         int sum=n[1];
    48         for(i=2;i<=6;i++){
    49             scanf("%d",&n[i]);
    50             sum+=n[i]*i;
    51         }
    52         if(sum==0) break;
    53         if(Case>1) printf("
    ");
    54         printf("Collection #%d:
    ",Case++);
    55         if(sum&1) printf("Can't be divided.
    ");
    56         else{
    57             int num=sum/2;
    58             bool flag[60005]={0};
    59             flag[0]=1;
    60             for(i=1;i<=6;i++){
    61                 int cnt[60005]={0};
    62                 for(j=0;j<=num-i;j++){
    63                     if(flag[j] && cnt[j]<n[i] && !flag[j+i]){
    64                         flag[j+i]=1;
    65                         cnt[j+i]=cnt[j]+1;
    66                         if(j+i==num) goto out;
    67                     }
    68                 }
    69             }
    70             out:;
    71             if(flag[num]) printf("Can be divided.
    ");
    72             else printf("Can't be divided.
    ");
    73         }
    74     }
    75     ///////////////////////////////////////////////////////////////////////
    76     return 0;
    77 }
    78 
    79 ///////////////////////////////////////////////////////////////////////////
    80 /*
    81 Testcase:
    82 Input:
    83 1 0 1 2 0 0
    84 1 0 0 0 1 1
    85 0 0 0 0 0 0
    86 Output:
    87 Collection #1:
    88 Can't be divided.
    89 
    90 Collection #2:
    91 Can be divided.
    92 */
    93 ///////////////////////////////////////////////////////////////////////////
  • 相关阅读:
    [12.19模拟赛]矩形|扫描线+set
    网 络
    数组(二维)
    数组
    02-线程的三种创建方式
    01-线程(概念篇)
    IO流-文件操作
    Serializable 可串行化接口
    PrintStream 类
    ObjectIntputStream / ObjectOutputStream 类
  • 原文地址:https://www.cnblogs.com/linqiuwei/p/3279046.html
Copyright © 2011-2022 走看看