uvalive5810 uva12368 Candles
题意:每组数据给出n个数,每个数在1-100,问组成这些数的蜡烛的权值的最小值。权值=把选的蜡烛从大到小排列组成的数
组成方式:比如有1 3两个蜡烛 可以组成13(1和3)或4(1+3) 只有一个加号可以用
解:位运算记录状态,can[i][j]表示在i的二进制所记录的状态下能不能组成j
can直接预处理出来,分类讨论 用一个数表示 还是用两个数表示 check的时候都在100以内 直接枚举
#include<cstdio>
#include<cmath>
#include<algorithm>
#include<cstring> using namespace std; int n;
bool can[][];
int a[];
int cas=; bool check1(int x,int y,int z){
int cnt[];
memset(cnt,,sizeof(cnt));
int tmp=y;
while (tmp!=){
int now=tmp%;
tmp=tmp/;
if (((x&(<<now))==)||(cnt[now]>)) return false;
cnt[now]++;
}
tmp=z;
while (tmp!=){
int now=tmp%;
tmp=tmp/;
if (((x&(<<now))==)||(cnt[now]>)) return false;
cnt[now]++;
}
return true;
} bool check(int x,int y){
if ((y<)&&(x&(<<y))) return true;
for (int i=;i<=y/;i++){
if (i!=(y-i)){
if (check1(x,i,y-i)) return true;
}
}
if (y==) return false;
int tmpy1=y/;
int tmpy2=y%;
if (tmpy1==tmpy2) return false;
if ((x&(<<tmpy1))==) return false;
if ((x&(<<tmpy2))==) return false;
return true;
} int main(){
memset(can,,sizeof(can));
for (int i=;i<;i++){
for (int j=;j<=;j++) can[i][j]=check(i,j);
}
while (){
scanf("%d",&n);
if (n==) return ;
cas++;
bool flag;
int ans=;
for (int i=;i<=n;i++) scanf("%d",&a[i]);
for (int i=;i<;i++){
flag=true;
for (int j=;j<=n;j++) if (!can[i][a[j]]) flag=false;
if (flag){
int tmp=;
for (int j=;j>=;j--) if (i&(<<j)) tmp=tmp*+j;
if ((ans==)||(ans>tmp)) ans=tmp;
}
}
printf("Case %d: %d\n",cas,ans);
}
return ;
}
/*
2 10 11
1 30
0
*/
uvalive5810 uva12368 Candles的更多相关文章
- C - New Year Candles
Problem description Vasily the Programmer loves romance, so this year he decided to illuminate his r ...
- codeforces A. New Year Candles 解题报告
题目链接:http://codeforces.com/problemset/problem/379/A 题目意思:给定a支蜡烛(每支蜡烛可以燃烧1小时),可以在燃尽的a支蜡烛中看能组成多少组b支蜡烛, ...
- ARC 101 C - Candles
题面在这里! 显然直接枚举左端点(右端点)就OK啦. #include<cstdio> #include<cstdlib> #include<algorithm> ...
- Gym - 101635K:Blowing Candles (简单旋转卡壳,求凸包宽度)
题意:给定N个点,用矩形将所有点覆盖,要求矩形宽度最小. 思路:裸体,旋转卡壳去rotate即可. 最远距离是点到点:宽度是点到边. #include<bits/stdc++.h> #de ...
- Gym101635K Blowing Candles
题目链接:http://codeforces.com/gym/101635 题目大意: 推荐一篇文章:https://blog.csdn.net/wang_heng199/article/detail ...
- Solution -「ABC 219H」Candles
\(\mathcal{Description}\) Link. 有 \(n\) 支蜡烛,第 \(i\) 支的坐标为 \(x_i\),初始长度为 \(a_i\),每单位时间燃烧变短 \(1\) ...
- Inverted sentences
And ever has it been that love knows not its own depth until the hour of separation. 除非临到了别离的时候,爱永远 ...
- Good Bye 2013 A
A. New Year Candles time limit per test 1 second memory limit per test 256 megabytes input standard ...
- HDU 5768:Lucky7(中国剩余定理 + 容斥原理)
http://acm.hdu.edu.cn/showproblem.php?pid=5768 Lucky7 Problem Description When ?? was born, seven ...
随机推荐
- jquery.validate的效验方式
jQuery校验官网地址:http://bassistance.de/jquery-plugins/jquery-plugin-validation 原文地址:http://www.cnblogs.c ...
- C语言入门(20)——使用VC2013对C语言进行调试
软件调试过程中,有时会一些逻辑和内存访问方面的问题,如果没有调试器的帮助,找出何处代码导致这块内存被更改是一件非常麻烦的事情.恰当运用数据断点可以快速帮我们定位问题的所在. 1.VC的调试快捷键 F5 ...
- Mysql 关键字-保留字(转帖)
2008-02-01 10:51 ADD ALL ALTER ANALYZE AND AS ASC ASENSITIVE BEFORE BETWEEN BIGINT BINARY BLOB BOTH ...
- 推荐一些C#相关的网站、资源和书籍(转载)
原文地址:http://blog.csdn.net/chinacsharper/article/details/17514923 一.网站 1.http://msdn.microsoft.com/zh ...
- structs常用的Action
今天座右铭-----谦虚使人进步,骄傲使人落后. 除了基本的Action之外,structs还提供几个其他的类型Action,下面就简单的说一下: 1.DispatchAction:能同时完成多个Ac ...
- 在Word中为标题样式添加自动编号功能
原文地址:http://blog.chinaunix.net/uid-16685753-id-2738270.html 摘要: 本文可以帮助你在Office 2007中为Word标题样式添加和设置自动 ...
- securecrt在linux与windows之间传输文件(转)
摘自:http://blog.csdn.net/rangf/article/details/6096365 SecureCRT这款SSH客户端软件同时具备了终端仿真器和文件传输功能.比ftp命令方便多 ...
- git使用三把斧
git status -查看哪些更改 git add file1 file2 ...
- The MySQL C API 编程实例
在网上找了一些MYSQL C API编程的文章,看了后认为还是写的不够充分,依据自己经验写了这篇<The MySQL C API 编程实例>,希望对须要调用到MYSQL的C的API的朋友有 ...
- sql server 存储过程分隔split
CREATE FUNCTION [dbo].[F_split] ( ), ) ) , ), f )) --实现split功能 的函数 AS BEGIN DECLARE @i INT SET @Sour ...