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 ...
随机推荐
- TableViewController的添加,删除,移动
#import "RootTableViewController.h" @interface RootTableViewController () { UITableViewCel ...
- Hibernate 命名查询NamedQuery (转)
转自:http://blog.163.com/ksm19870304@126/blog/static/374552332011993942391/ 配置方式: static List namedQue ...
- Windows Azure Service Bus 推动财务服务门户的高可用性和可伸缩性
抵押贷款公司和评估管理公司面临着快速.复杂且数据量极大的业务流程.他们需要可快速.轻松设置且容量几乎无限的可伸缩的企业级服务,来对处理评估订单以及自动化流程本身所产生的所有文档和数据进行管理. 这听起 ...
- 《小C QQ空间转帖、分享工具》之QQ空间数据传递的g_tk算法(C#)
原文地址:http://user.qzone.qq.com/419067339/2 public string GET_HTTP(string url, string referer_post, st ...
- I NEED A OFFER!
I NEED A OFFER! Time Limit : 2000/1000ms (Java/Other) Memory Limit : 65536/32768K (Java/Other) Tot ...
- C#编程规范
C#编程规范 Version 1.0 目录 第一章 概述.... 4 规范制定原则.... 4 术语定义.... 4 Pascal 大小写.... 4 Camel 大小写.... 4 文件命名组织 ...
- UIImage 图片处理:截图,缩放,设定大小,存储
图片的处理大概就分 截图(capture), 缩放(scale),设定大小(resize), 存储(save)这几样比较好处理, 另外还有滤镜,擦试等, 以后再说在这个Demo code裡, 我写了几 ...
- 提交时提示错误This Bundle is invalid.New apps and app updates submitted to the App Store must be built wit
this bundle is invalid . new apps and app updates submitted to the app store must be built with publ ...
- NotificationManager 发送通知
该应用的界面如下,界面代码在此不再给出,源码github账户下载 MainActivity.java public class MainActivity extends Activity { priv ...
- java.lang.NoClassDefFoundError: javax/servlet/jsp/jstl/core/LoopTag
异常原因:缺少jstl.jar包.一般在新建Web项目是jstl一项不要选none就不会出现这个问题.(还有可能就是缺少servlet-api.jar)