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)的更多相关文章

  1. CF922 CodeForces Round #461(Div.2)

    CF922 CodeForces Round #461(Div.2) 这场比赛很晚呀 果断滚去睡了 现在来做一下 A CF922 A 翻译: 一开始有一个初始版本的玩具 每次有两种操作: 放一个初始版 ...

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

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

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

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

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

  7. Codeforces Round #461 (Div. 2)B-Magic Forest+位运算或优雅的暴力

    Magic Forest 题意:就是在1 ~ n中找三个值,满足三角形的要求,同时三个数的异或运算还要为0: , where  denotes the bitwise xor of integers  ...

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

  9. Codeforces Round #354 (Div. 2) ABCD

    Codeforces Round #354 (Div. 2) Problems     # Name     A Nicholas and Permutation standard input/out ...

随机推荐

  1. 如何清理休眠文件(hiberfil.sys)

    如果使用了休眠功能,那么打开系统盘就会有一个很大(5.36G)的hiberfil.sys文件,它是将用户正在运行的程序,保存在这里,再启动系统就很快了.如要清理它(不用休眠功能,或者临时腾出空间),可 ...

  2. 2016.6.26——Maximum Depth of Binary Tree

    Maximum Depth of Binary Tree 本题收获 1.树时使用递归 2.注意边界条件时输出的值,仔细阅读题意,若是面试时,问清边界条件. 题目: Given a binary tre ...

  3. 【洛谷】P1445 没占到1444的愤怒

    继续洛谷刷水日常,突然遇到一道不是很水的题目…… https://www.luogu.org/problem/show?pid=1445 题意:给定n(1<=n<=1000000),求方程 ...

  4. springmvc与struts的区别

    一.拦截机制 1.Struts2 a.Struts2框架是类级别的拦截,每次请求就会创建一个Action,和Spring整合时Struts2的ActionBean注入作用域是原型模式prototype ...

  5. sql loader 控制文件使用十六进制分隔符

    最近项目中使用到了sql loader加载数据文件至数据库,提供的文件中使用了十六进制 7F5E 分隔符,在sql loader中如何加载呢? 经过查询实验后,控制文件ctl内容如下: load da ...

  6. 十六、springboot整合Spring-data-jpa(二)之通用DAO接口与添加自定义方法

    @NoRepositoryBean:Spring Data Jpa在启动时就不会去实例化BaseRepository这个接口 1.通用接口: import org.springframework.da ...

  7. 程序设计分层思想和DAO设计模式的开发

    无论是一个应用程序项目还是一个Web项目,我们都可以按照分层思想进行程序设计.对于分层,当下最流行划分方式是:表现层+控制层+业务层+数据层.其中,业务层和数据层被统称为后台业务层,而表现层和控制层属 ...

  8. [USACO16OPEN]248

    传送门啦 分析: 一个裸的区间dp,我们只需要注意合并的时候并不像2048那样加倍,每次都加1就好了 #include <iostream> #include <cstring> ...

  9. 以太坊go-ethereum常见问题汇总

    (1)什么是 Ethereum? 以太坊是一个分散的智能合同平台,由Ether的加密货币提供支持. (2) 听说过以太坊,但什么是Geth,Mist,Ethminer,Mix? Geth: 以太坊节点 ...

  10. Java工程师知识图谱

    一.Java工程师知识图谱(思维导图版) 二.Java工程师知识图谱(图文版) 三.Java工程师知识图谱(文字版) http://note.youdao.com/noteshare?id=615da ...