Codeforces Round #494 (Div 3) (A~E)
Codeforces 1003
这么做是不是不太好啊233


A.Polycarp's Pockets
#include <cstdio>
#include <cctype>
#include <algorithm>
#define gc() getchar()
const int N=500;
int n,A[N],tm[N];
inline int read()
{
int now=0,f=1;register char c=gc();
for(;!isdigit(c);c=='-'&&(f=-1),c=gc());
for(;isdigit(c);now=now*10+c-'0',c=gc());
return now*f;
}
int main()
{
n=read();
for(int i=1; i<=n; ++i) ++tm[read()];
int res=0;
for(int i=1; i<=100; ++i) res=std::max(res,tm[i]);
printf("%d",res);
return 0;
}
B.Binary String Constructing
#include <cstdio>
#include <cctype>
#include <algorithm>
#define gc() getchar()
const int N=10000;
int A,B,X;
char s[N];
inline int read()
{
int now=0,f=1;register char c=gc();
for(;!isdigit(c);c=='-'&&(f=-1),c=gc());
for(;isdigit(c);now=now*10+c-'0',c=gc());
return now*f;
}
int main()
{
A=read(),B=read(),X=read();//A:0 B:1
int n=A+B;
// if(X==1)
// {
// for(int i=1; i<=A; ++i) putchar('0');
// for(int i=A+1; i<=n; ++i) putchar('1');
// return 0;
// }
const char f=A>=B?'1':'0', s=A>=B?'0':'1';
if(A>B) std::swap(A,B);
for(int i=1; i<=X; ++i)
putchar((i&1)?s:f), --((i&1)?B:A);
if(X&1)
{
for(int i=X+1; i<=X+B; ++i) putchar(s);
for(int i=X+B+1; i<=n; ++i) putchar(f);
}
else
{
for(int i=X+1; i<=X+A; ++i) putchar(f);
for(int i=X+A+1; i<=n; ++i) putchar(s);
}
return 0;
}
C.Intense Heat
#include <cstdio>
#include <cctype>
#include <algorithm>
#define gc() getchar()
#define eps (1e-8)
const int N=5007;
int n,K,A[N];
inline int read()
{
int now=0,f=1;register char c=gc();
for(;!isdigit(c);c=='-'&&(f=-1),c=gc());
for(;isdigit(c);now=now*10+c-'0',c=gc());
return now*f;
}
int main()
{
n=read(),K=read();
for(int i=1; i<=n; ++i) A[i]=read();
double ans=0;
for(int i=1; i<=n; ++i)//O(n^2) 这种暴力我最会写了233
{
int sum=0;
for(int j=i; j<=n; ++j)
{
sum+=A[j];
if(j-i+1>=K) ans=std::max(ans,1.0*sum/(j-i+1));
}
}
printf("%.10lf",ans);
return 0;
}
D.Coins and Queries
#include <cmath>
#include <cstdio>
#include <cctype>
#include <cstring>
#include <algorithm>
#define gc() getchar()
const int N=2e5+5, INF=0x7fffffff;
int n,Q,A[N],tot[999],num[999];
inline int read()
{
int now=0;register char c=gc();
for(;!isdigit(c);c=gc());
for(;isdigit(c);now=now*10+c-'0',c=gc());
return now;
}
inline int Count(int x){
for(int i=0; i<31; ++i) if(x&(1<<i)) return i;
}
int Query()
{//写的好像麻烦了 当时非常zz
memcpy(num,tot,sizeof tot);
int B=read(),ans=0;
for(int i=30; ~i; --i)
{
if(!(B&(1<<i))) continue;
if(num[i]) ++ans;
else
{
int need=1<<i;
for(int j=i-1; ~j&&need; --j)
{
if(!num[j]) continue;
int v=std::min(num[j],need>>j);//need/(1<<j);//not ceil!
ans+=v, need-=v*(1<<j), num[j]-=v;
}
if(need) return -1;
}
}
return ans;
}
int main()
{
n=read(), Q=read();
for(int i=1; i<=n; ++i) ++tot[Count(read())];
while(Q--) printf("%d\n",Query());
return 0;
}
比赛结束后
E.Tree Constructing(贪心)
贪心策略显然 但可能要注意特殊情况(比如D=N-1,K=1)。
WA了四次结果结束后发现脑抽写错一行 改了就A了啊mmp
#include <cstdio>
#include <cctype>
#include <algorithm>
#define gc() getchar()
const int N=4e5+7,M=N<<1;
int n,D,K,now,dgr[N],Enum,H[N],nxt[M],to[M];
inline int read()
{
int now=0;register char c=gc();
for(;!isdigit(c);c=gc());
for(;isdigit(c);now=now*10+c-'0',c=gc());
return now;
}
inline void AddEdge(int u,int v)
{
++dgr[u], to[++Enum]=v, nxt[Enum]=H[u], H[u]=Enum;
++dgr[v], to[++Enum]=u, nxt[Enum]=H[v], H[v]=Enum;
}
void Link(int x,int dep)
{
if(!dep) return;
for(int i=K-dgr[x]; i>0&&now<n; --i) AddEdge(x,++now), Link(now,dep-1);
}
bool Solve()
{
if(D>=n) return 0;
for(int i=1; i<=D; ++i) AddEdge(i,i+1);
now=D+1;
for(int i=2; i<=D&&now<n; ++i) Link(i,D-std::max(i-1,D+1-i));
for(int i=1; i<=n; ++i) if(dgr[i]>K) return 0;
// DFS1(1,1,0), Max=0, DFS1(V,V,0);
// if(Max!=D) return 0;
return now>=n;
}
void DFS_for_Ans(int x,int f)
{
for(int i=H[x]; i; i=nxt[i])
if(to[i]!=f) printf("%d %d\n",x,to[i]), DFS_for_Ans(to[i],x);
}
int main()
{
n=read(), D=read(), K=read();
if(Solve()) puts("YES"), DFS_for_Ans(1,1);
else puts("NO");
return 0;
}
F.Abbreviation
待补
Codeforces Round #494 (Div 3) (A~E)的更多相关文章
- Codeforces Round #494 (Div. 3)
刚好在考完当天有一场div3,就开了个小号打了,打的途中被辅导员喊去帮忙,搞了二十分钟-_-||,最后就出了四题,题解如下:题目链接:http://codeforces.com/contest/100 ...
- Codeforces Round #494 (Div. 3) D. Coins and Queries(贪心
题目链接 题目大意:给你n个物品,第iii个物品价值aia_iai,询问q次,问你能不能凑出价值为qiq_iqi的物品. 小贪心吧.从大到小找,能拿就拿就行了. #include<bits/ ...
- Codeforces Round #494 (Div. 3) D. Coins and Queries (贪心,数学)
题意:给你一组全是\(2^d\ (d\ge0)\)的数,询问q次,每次询问一个数,问这个数是否能够由原数组中的数相加得到,如果能,输出最少用多少个数,否则输出\(-1\). 题解:首先贪心得出结论:如 ...
- 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 ...
- Codeforces Round #368 (Div. 2)
直达–>Codeforces Round #368 (Div. 2) A Brain’s Photos 给你一个NxM的矩阵,一个字母代表一种颜色,如果有”C”,”M”,”Y”三种中任意一种就输 ...
- cf之路,1,Codeforces Round #345 (Div. 2)
cf之路,1,Codeforces Round #345 (Div. 2) ps:昨天第一次参加cf比赛,比赛之前为了熟悉下cf比赛题目的难度.所以做了round#345连试试水的深浅..... ...
- Codeforces Round #279 (Div. 2) ABCDE
Codeforces Round #279 (Div. 2) 做得我都变绿了! Problems # Name A Team Olympiad standard input/outpu ...
- Codeforces Round #262 (Div. 2) 1003
Codeforces Round #262 (Div. 2) 1003 C. Present time limit per test 2 seconds memory limit per test 2 ...
随机推荐
- curator框架的使用以及实现分布式锁等应用与zkclient操作zookeeper,简化复杂原生API
打开zookeeper集群 先体会一下原生API有多麻烦(可略过): //地址 static final String ADDR = "192.168.171.128:2181,192.16 ...
- 1 - django-介绍-MTV-命令-基础配置-admin
目录 1 什么是web框架 2 WSGI 3 MVC与MTV模式 3.1 MVC框架 3.2 MTV框架 3.3 区别 4 django介绍 4.1 Django处理顺序 4.2 创建django站点 ...
- DirectFB简介以及移植[一]【转】
转自:https://blog.csdn.net/wavemcu/article/details/39251805 ****************************************** ...
- python字典解析
import json # coding: utf-8 from functools import singledispatch from collections import abc import ...
- kettle简单插入与更新
Kettle简介:Kettle是一款国外开源的ETL工具,纯java编写,可以在Window.Linux.Unix上运行,数据抽取高效稳定.Kettle 中文名称叫水壶,该项目的主程序员MATT 希望 ...
- 【2017-10-1】雅礼集训day1
今天的题是ysy的,ysy好呆萌啊. A: 就是把一个点的两个坐标看成差分一样的东西,以此作为区间端点,然后如果点有边->区间没有交. B: cf原题啊.....均摊分析,简单的那种. 线段树随 ...
- TCP连接建立与断开
tcp状态 LISTEN:侦听来自远方的TCP端口的连接请求 LISTEN:侦听来自远方的TCP端口的连接请求 SYN-SENT:再发送连接请求后等待匹配的连接请求 SYN-RECEIVED:再收到和 ...
- C++之可调用对象
C++中的可调用对象分为以下几种: 函数 函数指针 lambda表达式 bind创建的对象 重载了函数调用运算符(即“()”)的类 函数.函数指针不再介绍.lambda表达式与bind创建的类参考—— ...
- Linux学习笔记:pwd与dirs的区别
在Linux中可以使用pwd和dirs进行当前目录查看,分别用于显示当前目录和显示完整目录记录.具体如下: 1.pwd 显示当前目录 2.dirs 显示目录堆叠中的记录 END 2018-08-21 ...
- poj 2369(置换群)
Permutations Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 3041 Accepted: 1641 Desc ...