zoukankan      html  css  js  c++  java
  • tyvj1194 划分大理石

    描述

    有价值分别为1..6的大理石各a[1..6]块,现要将它们分成两部分,使得两部分价值之和相等,问是否可以实现。其中大理石的总数不超过20000。 

    输入格式

    有多组数据!
    所以可能有多行
    如果有0 0 0 0 0 0表示输入文件结束
    其余的行为6个整数

    输出格式

    有多少行可行数据就有几行输出
    如果划分成功,输出Can,否则Can't

    测试样例1

    输入

    4 7 4 5 9 1 
    9 8 1 7 2 4 
    6 6 8 5 9 2 
    1 6 6 1 0 7 
    5 9 3 8 8 4 
    0 0 0 0 0 0

    输出

    Can't 
    Can 
    Can't 
    Can't 
    Can
    #include<cstdio>
    #include<iostream>
    #include<algorithm>
    #include<cstring>
    #include<string>
    using namespace std;
    const int maxn = 20505;
    int n,sum,a[10],w[maxn];
    bool f[maxn];
    int main(){
        bool ok = true,ans = false;
        while(ok){
            ok = false;
            n = sum = 0;
            for(int i = 1;i <= 6;i++){
                scanf("%d",&a[i]);
                if(a[i]) ok = true;
                sum += a[i]*i;
                for(int j = 1;j <= a[i];j<<=1){
                    w[++n] = j * i;
                    a[i] -= j;
                }
                w[++n] = a[i] * i;
            }
            if(!ok) break;
            if(sum & 1){
                puts("Can't");
                continue;
            }
            memset(f,false,sizeof(f));
            f[0] = true;
            for(int i = 1;i <= n;i++){
                for(int j = sum >> 1;j >= w[i];j--){
                    if(f[j - w[i]]) f[j] = true;
                }
                if(f[sum>>1]){
                    ans = true;
                    break;
                }
            }
            if(ans) puts("Can");
            else puts("Can't");
        }
        return 0;
    }
  • 相关阅读:
    上传下载---上传
    分页中的难点
    分页的实现
    c3p0-config连接池
    判断
    客户关系管理增删改
    转发和重定向
    dbUtils结果集处理器
    加载配置文件.properties,及面向接口编程的DaoFactory
    jdbc链接数据库mysql
  • 原文地址:https://www.cnblogs.com/hyfer/p/5754659.html
Copyright © 2011-2022 走看看