数据不是很大,直接枚举约数,判断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的更多相关文章

  1. 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 ...

  2. 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 ...

  3. 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 ...

  4. 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 ...

  5. JSU 2013 Summer Individual Ranking Contest - 5

    JSU 2013 Summer Individual Ranking Contest - 5 密码:本套题选题权归JSU所有,需要密码请联系(http://blog.csdn.net/yew1eb). ...

  6. 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 ...

  7. 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 ...

  8. 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 ...

  9. 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:  ...

随机推荐

  1. shell脚本初识

    #!/bin/bash(linux脚本环境的声明即解释器,该解释器为bash,位于根目录下的bin目录下) 变量的定义与赋值: 格式:变量名=变量值(无需声明变量类型) 变量的引用: 格式:$变量名 ...

  2. ASP.NET MVC 应用程序的安全性,看一眼你就会了

    1.使用Authorize特性登陆对于我们开发程序而言,基本上都是要求角色成员使用Authorize特性,比如,对于管理员而言角色是Admin,对于登陆注册登陆用户而言是User那么我们在用户登陆的时 ...

  3. UDP HelloWord

    Client.cpp #include <stdio.h> #include <winsock2.h> #pragma comment (lib,"ws2_32&qu ...

  4. 修改UI中的值,无反应解决办法

    var targetObj = $("<input name='mydate' class='easyui-datebox'>").appendTo("#id ...

  5. python学习第三天第一部分

    字典 1.字典的定义和规则: 定义:{key1:value1,key2:value2} key 的定义规则:1.必须是不可变的(数字.字符串.元组):2.必须是唯一的, value的定义规则:任意类型 ...

  6. Python 初学——V_Rename(第一个完整的python程序)

    我在大一的时候就对python非常感兴趣,就是一直没有时间和机会去学习下,只是了解些表面的东西,今天早上整理电脑的时候发现文件夹里面的文件名是这样子的,有点小不舒服,特别想去除重复的"Str ...

  7. selenium+python 浏览器标签页跳转 switch_to_window

    浏览器页面跳转方法记录: from selenium import webdriver import time browser = webdriver.Chrome() first_url='http ...

  8. Arrays.asList方法总结

    import java.util.Arrays; import java.util.List; /** * * 本类演示了Arrays类中的asList方法 * 通过四个段落来演示,体现出了该方法的相 ...

  9. Leeo 智能夜灯:默默守护你的家

    http://www.ifanr.com/462377 Leeo 智能夜灯是一个低调的设备.它不需要你与之交互,也不会产生多余的费用.当你把它插到墙上插座,然后下载应用后,就不用再管它了.然后,它就开 ...

  10. 【go】sdk + idea-plugin 开发工具安装

    http://golang.org/doc/install/source 第一步:windows 安装 git第二步$ git clone https://go.googlesource.com/go ...