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. 凸包入门(Graham扫描法)(A - Wall POJ - 1113)

    题目链接:https://cn.vjudge.net/contest/276359#problem/A 题目大意:有一个国王,要在自己的城堡周围建立围墙,要求围墙能把城堡全部围起来,并且围墙距离城堡的 ...

  2. sqlplus设置长度

    1.set linesize   100 2.col  XX format  a30 3.col  XXX format 9,999,999,999 3.set heading off  表头不显示

  3. oracle 创建表空间 、用户 、赋权、建表

    一.创建表空间 1.创建临时表空间 create temporary tablespace TS_TEM_TAB_SPACE tempfile 'D:\oracle\TS_TEM_TAB_SPACE. ...

  4. 聊天室(上篇)GatewayWorker 基础

    前言 本文的目的是基于 GatewayWorker 官方手册,梳理一次 GatewayWorker,并在实践中与 MVC 框架整合的思路(附最终的项目源码).如果你已经理解了整合这一块儿的知识,那么就 ...

  5. DevExpress 行事历(Scheduler)的常用属性、事件和方法

    一.TcxScheduler[TcxScheduler常用属性]1.Storage    - 邦定一个Storage为Scheduler显示提供数据 2.DateNavigate.ColCount   ...

  6. WebApi Owin SelfHost OAuth2 - 授权服务和资源服务分离方案

    使用JWT 参考:http://www.cnblogs.com/grissom007/p/6294746.html

  7. 数据库-mysql索引

    MySQL 索引 MySQL索引的建立对于MySQL的高效运行是很重要的,索引可以大大提高MySQL的检索速度. 打个比方,如果合理的设计且使用索引的MySQL是一辆兰博基尼的话,那么没有设计和使用索 ...

  8. java基础35 双例集合Map及其常用方法

    单例集合体系: ---------| collection  单例集合的根接口--------------| List  如果实现了list接口的集合类,具备的特点:有序,可重复       注:集合 ...

  9. SQL行列转换的另一种方法

    create table tb(姓名 varchar(10) , 课程 varchar(10) , 分数 int)insert into tb values('张三' , '语文' , 74)inse ...

  10. LeetCode691. Stickers to Spell Word

    We are given N different types of stickers. Each sticker has a lowercase English word on it. You wou ...