Codeforces Round #461 (Div. 2)
A - Cloning Toys
/*
题目大意:给出两种机器,一种能将一种原件copy出额外一种原件和一个附件,
另一种可以把一种附件copy出额外两种附件,给你一个原件,
问能否恰好变出题目要求数量的原件和附件
题解:注意当附件需求不为0的时候,原件需求必须大于1
*/
#include <cstdio>
#include <algorithm>
int main(){
int a,b;
scanf("%d%d",&a,&b);
if((a-b+1)%2==0&&a-b+1>=0&&b>1||(a==0&&b==1))puts("Yes");
else puts("No");
return 0;
}
B - Magic Forest
/*
题目大意:求n以内的三个数字使得其异或和为0且能构成三角形的三边
*/
#include <cstdio>
#include <algorithm>
using namespace std;
int n,ans=0;
int main(){
scanf("%d",&n);
for(int i=1;i<=n;i++){
for(int j=i+1;j<=n;j++){
int k=i^j;
if(k<i+j&&k>j&&k<=n)ans++;
}
}printf("%d\n",ans);
return 0;
}
C - Cave Painting
/*
题目大意:问是否n对1-k的数取模答案均不相同
题解:要达到题目要求,我们发现有n%i=i-1,即(n+1)%i=0
*/
#include <cstdio>
#include <cstring>
using namespace std;
long long n,k;
int main(){
scanf("%lld%lld",&n,&k);
for(long long i=1;i<=k;i++){
if((n+1)%i){puts("No");return 0;}
}puts("Yes");
return 0;
}
D - Robot Vacuum Cleaner
/*
题目大意:给出一些s和h组成的串,求将其拼合在一起能组成的最多的sh序列
题解:我们发现拼接顺序的变化只对相邻两个串的答案有影响,所以我们根据这点排序,
然后顺序统计即可
*/
#include <cstdio>
#include <algorithm>
#include <cstring>
using namespace std;
const int N=100010;
struct data{long long s,h;}p[N];
bool cmp(data a,data b){
return a.s*b.h>a.h*b.s;
}
char s[N];
int n;
long long ans=0;
int main(){
scanf("%d",&n);
for(int i=1;i<=n;i++){
p[i].s=0; p[i].h=0;
scanf("%s",s);
int len=strlen(s);
for(int j=0;j<len;j++){
if(s[j]=='s')p[i].s++;
if(s[j]=='h'){ans+=p[i].s;p[i].h++;}
}
}sort(p+1,p+n+1,cmp);
long long S=0;
for(int i=1;i<=n;i++){
ans+=S*p[i].h;
S+=p[i].s;
}printf("%lld\n",ans);
return 0;
}
E - Birds
/*
题目大意:每棵树召唤鸟的代价都是不同的,每棵树上最多有c只鸟,
每当召唤一只鸟魔法上限会提升,每走到下一棵树魔法会回复X,但是最多不能超过上限,
不能往回走,问最多能召唤几只鸟
题解:dp[i][j]表示到达第i棵树一共召唤了j只鸟剩余的mana值,
只要大于等于0即表示该状态可达,用背包问题求解dp即可
*/
#include <cstdio>
#include <algorithm>
#include <cstring>
using namespace std;
typedef long long LL;
LL dp[1010][10010],W,B,X,C=0;
int n,cost[1010],c[1010];
int main(){
memset(dp,0x80,sizeof(dp));
scanf("%d%lld%lld%lld",&n,&W,&B,&X);
dp[0][0]=W;
for(int i=1;i<=n;i++)scanf("%d",&c[i]),C+=c[i];
for(int i=1;i<=n;i++)scanf("%d",&cost[i]);
for(int i=1;i<=n;i++){
for(int j=0;j<=C;j++){
LL nw=dp[i-1][j];
if(nw<0)continue;
for(LL k=0;k<=c[i]&&k*cost[i]<=nw;k++)dp[i][j+k]=max(dp[i][j+k],nw-k*cost[i]);
}
for(int j=0;j<=C;j++)dp[i][j]=min(dp[i][j]+X,B*j+W);
}
for(int i=C;i>=0;i--)if(dp[n][i]>=0){
printf("%d\n",i);
return 0;
}
}
F - Divisibility
/*
题目大意:给出n和k,要求找出数字大小在n以内的非重集合,使得集合中存在恰好k对a和b,
满足a能整除b
题解:我们先用nlogn的时间预处理出每个数被其小的数整除的次数di,
我们可以通过均摊logn的单次复杂度计算出一个数被比其大的数整除的次数,
那么我们就能比较快地得到一个数对于答案的影响
我们先随意去除一些di大于1的数,然后用较小的碎块去凑k这个整数,
如果无法凑出来,则不可行
*/
#include <cstdio>
#include <algorithm>
using namespace std;
const int N=300010;
int n,k,d[N],b[N],tot=0,ans=0;
int main(){
scanf("%d%d",&n,&k);
for(int i=1;i<=n;i++){
b[i]=1; for(int j=i+i;j<=n;j+=i)d[j]++,tot++;
}
for(int i=n;i>1;i--){
int s=d[i];
for(int j=i+i;j<=n;j+=i)if(b[j])s++;
if(tot-s>=k&&d[i]>1){
tot-=s;
b[i]=0; for(int j=i+i;j<=n;j+=i)d[j]--;
}
}
for(int i=n;i>=1;i--){
int s=d[i];
for(int j=i+i;j<=n;j+=i)if(b[j])s++;
if(tot-s>=k&&b[i]){
tot-=s;
b[i]=0; for(int j=i+i;j<=n;j+=i)d[j]--;
}
}
for(int i=1;i<=n;i++)ans+=b[i];
if(tot!=k){puts("No");return 0;}
puts("Yes");
printf("%d\n",ans);
for(int i=1;i<=n;i++)if(b[i])printf("%d ",i);
return 0;
}
Codeforces Round #461 (Div. 2)的更多相关文章
- CF922 CodeForces Round #461(Div.2)
CF922 CodeForces Round #461(Div.2) 这场比赛很晚呀 果断滚去睡了 现在来做一下 A CF922 A 翻译: 一开始有一个初始版本的玩具 每次有两种操作: 放一个初始版 ...
- Codeforces Round #461 (Div. 2) B C D
题目链接:http://codeforces.com/contest/922 B. Magic Forest time limit per test 1 second memory limit per ...
- Codeforces Round #461 (Div. 2) D. Robot Vacuum Cleaner
D. Robot Vacuum Cleaner time limit per test 1 second memory limit per test 256 megabytes Problem Des ...
- Codeforces Round #461 (Div. 2) C. Cave Painting
C. Cave Painting time limit per test 1 second memory limit per test 256 megabytes Problem Descriptio ...
- Codeforces Round #461 (Div. 2) B. Magic Forest
B. Magic Forest time limit per test 1 second memory limit per test 256 megabytes Problem Description ...
- Codeforces Round #461 (Div. 2) A. Cloning Toys
A. Cloning Toys time limit per test 1 second memory limit per test 256 megabytes Problem Description ...
- Codeforces Round #461 (Div. 2)B-Magic Forest+位运算或优雅的暴力
Magic Forest 题意:就是在1 ~ n中找三个值,满足三角形的要求,同时三个数的异或运算还要为0: , where denotes the bitwise xor of integers ...
- Codeforces Round #366 (Div. 2) ABC
Codeforces Round #366 (Div. 2) A I hate that I love that I hate it水题 #I hate that I love that I hate ...
- Codeforces Round #354 (Div. 2) ABCD
Codeforces Round #354 (Div. 2) Problems # Name A Nicholas and Permutation standard input/out ...
随机推荐
- boost::bind的使用
最近在几经波折之后,终于对于boost::bind有点理解了.对于习惯了其他语言的人来说,boost::bind是个挺神奇的东西,它可以将你的方法适配成任何其他的方法.其实这得益于c++的模板以及操作 ...
- Ubuntu_安装Wiz笔记
前言 安装完成了Linux,有了搜狗输入法,我们还需要笔记软件,本文主要介绍如何安装为知笔记 安装步骤 找到wiz官网:http://www.wiz.cn/ 获取Linux安装教程 安装QT 下载的Q ...
- @RequestParam,@PathParam,@PathVariable,@QueryParam注解的使用区别
获取url模板上数据的(/{id})@DefaultValue 获取请求参数的(包括post表单提交)键值对(?param1=10¶m2=20).可以设置defaultValue JA ...
- 14 Go's Declaration Syntax go语言声明语法
Go's Declaration Syntax go语言声明语法 7 July 2010 Introduction Newcomers to Go wonder why the declaration ...
- 一种获取xml文件某个节点内容的shell方法
配置文件 config.xml <xml> <server> <name>srv-01</name> </server> <serve ...
- 使用插件实现Jenkins参数化构建
一.插件安装 1.打开插件管理,在此界面可以安装插件 二.参数化 1.在“可选插件”中查找如下两个插件然后安装,安装后重启Jenkins Build With Parameters 输入框式的参数 P ...
- 奇妙的CSS之CSS3新特性总结
随着CSS3标准的发布,越来越多的浏览器开始支持最新的CSS标准,虽然还有些新特性支持的不够完美,但相信未来的浏览器一定会完全支持CSS3的,毕竟这代表着大趋势!下面l列出来一些CSS3中出现的新特性 ...
- Java事务管理之Hibernate
环境与版本 Hibernate 版本:Hibernate 4.2.2 (下载后的文件名为hibernate-release-4.2.2.Final.zip,解压目录hibernate-release- ...
- Effective STL 学习笔记14: Use reserve to avoid unnecessary reallocations.
vector 和 string 容器在动态插入一个新的对象时,如果容器内空间不够,该容器会: 重新分配空间 通常的做法是分配当前 Capacity 大小两倍的空间. 将旧空间中的所有元素拷贝进新的空间 ...
- 开源框架:SDWebImage
http://blog.csdn.net/uxyheaven/article/details/7909373 SDWebImage是我搞iOS以来少数佩服的框架,膜拜一下作者.真的写的非常棒! 这套开 ...