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: ...
随机推荐
- SharedSDK微信分享不成功,分享之后没有反应
对于一般来说,使用SharedSDK的时候,分享不成功不外乎下面几个原因: 1.测试没有打包2.打包的keystore跟微信开放平台上面的不一致, 导致MD5码不一致3.分享参数错误4.应用没有审核通 ...
- Redis 一:安装篇
.安装环境,虚拟机 + centos6. PS::前提已经安装了yum的情况下 第一步:安装 mkdir /usr/redis 新建redis目录 cd /usr/redis 进入目录 wget ht ...
- php学习日志(5)-解决Windows Live Writer错误:WindowsLive.Writer.CoreServices.HttpRequestHelper的类型初始值设定发生异常
以前用Windows Live Writer写日志都好好的,前几天用写完日志,点击发布,突然弹出意外错误:“WindowsLive.Writer.CoreServices.HttpRequestHel ...
- Win7开始菜单之【附件】不全解决方案
Win7开始菜单之[附件]不全解决方案 1:打开你的[开始]菜单,转到附件,如果你发现你的附件里的“附件”不是那么全的话,如下图:来吧,我告诉你如何恢复它到最初的模样……哦,或许如果你不急于恢复的话, ...
- 使用wget备份禅道
禅道7.1,管理了公司所有项目.需要每月备份. 主机安装在一台windows上.为了方便,写个脚本自动调用禅道的备份功能,并把服务器上的备份文件下载到本地. @echo off setlocal re ...
- Basic Vlan Configure
Basic Vlan CLI Configure Switch>en Switch#conf t Enter configuration commands, one per line. End ...
- VirtualBox虚拟机安装MSDOS和MINIX2.0.0双系统
1. 在VirtualBox中新建一个MSDOS虚拟机. 2.下载一个MSDOS软盘镜像. 3.启动虚拟机,提示选择安装盘时,选择步骤2下载过来的MSDOS镜像. 4.正常启动进入DOS命令行,用FD ...
- makefile教程网址
http://www.cnblogs.com/wang_yb/p/3990952.html
- redis 界面软件使用
ubuntu 下下载安装包 sudo dpkg -i redis-desktop-manager_0.8.3-120_amd64.deb//安装 redis-desktop-manager //启动
- windows2003服务器不显示桌面怎么办
ctrl +alt+delete 进入任务管理器应用程序里 创建新任务 C:\WINDOWS\explorer.exe 运行就行