2013 Multi-University Training Contest 1 Cards
数据不是很大,直接枚举约数,判断4个条件是否满足!
这样就得到4种卡片,总共2^4种情况,枚举各种情况即可!!!
#include<iostream>
#include<cmath>
#include<algorithm>
#define MAX 5000005
#define ll long long
using namespace std;
bool ispri[MAX];
int extra[];
struct card
{
int score,num,s;
}p[];
bool cmp(const card &aa,const card &bb){
return aa.score>bb.score?:;
}
void init(){
ll i,j;
ispri[]=;
for (i=;i<MAX;i++){
if (ispri[i]==){
for (j=i*i;j<MAX;j+=i)
ispri[j] = ;
}
}
}
void factor(int n,int k){
ll i,j,num=,sum=,mul=,t;
for (i=;i*i<=n;i++){
if (n%i==){
num ++;
sum += i;
mul = (ll)mul*i;
if (i*i != n){
num ++;
sum += n/i;
mul = (ll)mul*(n/i);
}
if (mul == (ll)n*n)
mul = ;
}
}
p[k].s = ;j = ;
if (ispri[n]==){
p[k].s |= (<<);
j ++;
}
if (ispri[num]==){
p[k].s |= (<<);
j ++;
}
if (ispri[sum]==){
p[k].s |= (<<);
j ++;
}
t = (ll)sqrt(mul+0.0);
if (t*t==mul||(t+)*(t+)==mul||(t-)*(t-)==mul){
p[k].s |= (<<);
j++;
}
p[k].score = j;
}
int main(){
init();
int t,i,j,k,n,aa;
cin>>t;
while (t--){
cin>>n>>k;
for (i=;i<n;i++){
cin>>aa>>p[i].num;
if (aa==){
p[i].score = ;
p[i].s = (<<);
}
else factor(aa,i);
}
for (i=;i<;i++){
cin>>extra[i];
}
cout<<p[].score;
for (i=;i<n;i++){
cout<<' '<<p[i].score;
}
cout<<endl;
sort(p,p+n,cmp);
ll ans = -(<<);
for (i=;i<(<<);i++){
ll temp=,an=k,flag=;
for (j=;j<n;j++){
if ((i&p[j].s)==){
if (p[j].num < an){
temp += p[j].score*p[j].num;
an -= p[j].num;
flag |= p[j].s;
}
else{
temp += p[j].score*an;
an = ;
flag |= p[j].s;
break;
}
}
}
for (j=;j<;j++){
if ((flag&(<<j))==)
temp += extra[j];
}
if (an != ) continue;
else ans = max(ans,temp);
}
cout<<ans<<endl;
}
return ;
}
2013 Multi-University Training Contest 1 Cards的更多相关文章
- Integer Partition(hdu4658)2013 Multi-University Training Contest 6 整数拆分二
Integer Partition Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) T ...
- Partition(hdu4651)2013 Multi-University Training Contest 5
Partition Time Limit: 6000/3000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) Total Sub ...
- ACM ICPC Central Europe Regional Contest 2013 Jagiellonian University Kraków
ACM ICPC Central Europe Regional Contest 2013 Jagiellonian University Kraków Problem A: Rubik’s Rect ...
- Partition(hdu4651)2013 Multi-University Training Contest 5----(整数拆分一)
Partition Time Limit: 6000/3000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) Total Sub ...
- JSU 2013 Summer Individual Ranking Contest - 5
JSU 2013 Summer Individual Ranking Contest - 5 密码:本套题选题权归JSU所有,需要密码请联系(http://blog.csdn.net/yew1eb). ...
- HDU4888 Redraw Beautiful Drawings(2014 Multi-University Training Contest 3)
Redraw Beautiful Drawings Time Limit: 3000/1500 MS (Java/Others) Memory Limit: 65536/65536 K (Jav ...
- hdu 4930 Fighting the Landlords--2014 Multi-University Training Contest 6
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4930 Fighting the Landlords Time Limit: 2000/1000 MS ...
- HDU 2018 Multi-University Training Contest 3 Problem A. Ascending Rating 【单调队列优化】
任意门:http://acm.hdu.edu.cn/showproblem.php?pid=6319 Problem A. Ascending Rating Time Limit: 10000/500 ...
- 2015 Multi-University Training Contest 8 hdu 5383 Yu-Gi-Oh!
Yu-Gi-Oh! Time Limit: 2000ms Memory Limit: 65536KB This problem will be judged on HDU. Original ID: ...
随机推荐
- iOS开发笔记-两种单例模式的写法
iOS开发笔记-两种单例模式的写法 单例模式是开发中最常用的写法之一,iOS的单例模式有两种官方写法,如下: 不使用GCD #import "ServiceManager.h" ...
- WP开发笔记——控件倾斜效果
创建一个基本的 Windows Phone 应用程序并添加 TiltEffect 类文件. 添加要倾斜的控件的分类. 全局应用 IsTiltEnabled 依赖项属性,以便为所有的指定控件提供倾斜功能 ...
- Silverlight C#动态设置样式
1.从页面资源中获取样式并应用 btnTest.Style = (Style)this.Resources["BigButtonStyle"] 2.从项目中单独分开的资源字典文件( ...
- fastclick插件 导致 input[type="date"] 无法触发问题解决方案
鄙人才疏学浅,新人一枚,不足之处还请谅解,写下这个也只是为了给大家分享一下我解决这个BUG的方法,也是自己的一个笔记. 首先,我们使用fastclick插件的初衷是解决“tap”事件“点透”的BUG: ...
- Global::pickSpecificClass_DNT
/*************************************************** Created Date: 13 Jul 2013 Created By: Jimmy Xie ...
- 第22章 项目3:万能的XML
Mix-in:混入类,是一种Python程序设计中的技术,作用是在运行期间动态改变类的基类或类的方法,从而使得类的表现可以发生变化.可以用在一个通用类接口中. 在实践一个解析XML文件的实践中,体会动 ...
- Microsoft server software support for Microsoft Azure virtual machines
http://support.microsoft.com/kb/2721672/en-us Article ID: 2721672 - Last Review: November 22, 2014 ...
- 【转载】mysql 四种隔离级别分析
sql标准中,有四种隔离级别,各个离级别都有各自的规则,隔离级别越低,允许并发越大,消耗的资源越少,但是越不安全,下面就mysql数据库来分别介绍一下(每个存储引擎实施的隔离级别会有稍微的不同)mys ...
- 深入理解ThreadLocal(一)
Android里,在不同的线程(假设子线程已经创建了Looper)中创建Handler时,并不需要显式指定Looper,系统能自动找到该线程自己的Looper.不同线程的Looper相互独立,之所以能 ...
- Android crop image size
private void performCrop() { try { //call the standard crop action intent (the user device may not s ...