Codeforces Round #398 (Div. 2) A-E
分数史上新低
开场5分钟过了A题,想着这次赌一把手速,先去切C吧
看完C题觉得这应该是道水题,码了十分钟提交,WA
想着这明明是道水题,估计少考虑了情况,添了几行再交,WA
不可能啊,这题都A不掉,和SB有什么区别
(开始半小时后)A不掉啊,要不去做别的题吧,啊不行,不能对不起我写了这么久的代码,继续debug
(开始一小时后)心态崩了,辣鸡比赛我不玩了。关了CF跑去写了半道主席树
(倒数半小时)反正要掉分,今天和这C题死磕吧
(结束看题解)结论:我和SB有什么区别
(第二天写BDE题)卧槽这么简单我为什么看都没看,我和SB有什么区别*3

A. Snacktower
要搭一座数字下面大上面小的树塔,但数字出现的顺序不定。
每个时刻拿到一个数字,不能堆到塔上就扔到堆里,能就建塔
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cstring>
#include<queue>
using namespace std;
const int mxn=;
int read(){
int x=,f=;char ch=getchar();
while(ch<'' || ch>''){if(ch=='-')f=-;ch=getchar();}
while(ch>='' && ch<=''){x=x*-''+ch;ch=getchar();}
return x*f;
}
priority_queue<int>q;
bool f[mxn];
int main(){
int i,j,x;
int n=read();
f[n+]=;
for(i=;i<=n;i++){
x=read();
q.push(x);
while(!q.empty() && f[q.top()+]){
f[q.top()]=;
printf("%d ",q.top());
q.pop();
}
printf("\n");
}
return ;
}
A
B.The Queue
模拟,贪心找到一个适合的插入点。
如果所有人都处理完了,营业还没结束,那主角可以等到最后再过去
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cstring>
#include<queue>
#define LL long long
using namespace std;
const int mxn=;
LL read(){
LL x=,f=;char ch=getchar();
while(ch<'' || ch>''){if(ch=='-')f=-;ch=getchar();}
while(ch>='' && ch<=''){x=x*-''+ch;ch=getchar();}
return x*f;
}
LL ts,tf,t;
LL w[mxn];
int main(){
int i,j;
ts=read();tf=read();
t=read();
int n=read();
for(i=;i<=n;i++){w[i]=read();}
if(w[]>ts){printf("%I64d\n",ts);return ;}
LL ans=1e15,pos=-;
LL smm=ts,last=;
for(i=;i<=n;i++){
last=smm-w[i]+;
if(last<=){
printf("%I64d\n",w[i]-);
return ;
}
if(smm+t>tf)break;
if(last<ans){
ans=last;pos=w[i]-;
}
smm+=t;
}
if(smm+t<=tf)pos=smm;
printf("%I64d\n",pos);
return ;
}
B
C. Garland
把一棵树分成权值和相等的三部分
明明只是一个DFS?
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cstring>
#include<queue>
using namespace std;
const int mxn=;
int read(){
int x=,f=;char ch=getchar();
while(ch<'' || ch>''){if(ch=='-')f=-;ch=getchar();}
while(ch>='' && ch<=''){x=x*-''+ch;ch=getchar();}
return x*f;
}
struct edge{
int v,nxt;
}e[mxn<<];
int hd[mxn],mct=;
void add_edge(int u,int v){
e[++mct].v=v;e[mct].nxt=hd[u];hd[u]=mct;return;
}
int w[mxn];
int sz[mxn];
int n,smm=,rt;
int ans[],cnt=;
int f[mxn];
void DFS(int u){
f[u]=;
sz[u]+=w[u];
for(int i=hd[u];i;i=e[i].nxt){
int v=e[i].v;
DFS(v);
sz[u]+=sz[v];
// if(sz[v]==smm){f[v]=v;}
if(f[u] && f[v]){
ans[]=f[u];
ans[]=f[v];
}
if(f[v])f[u]=f[v];
}
/*
cnt=0;
for(int i=hd[u];i;i=e[i].nxt){
int v=e[i].v;
if(f[v]){
f[u]=f[v];
if(f[v]!=ans[1])ans[++cnt]=f[v];
if(cnt==2){
printf("%d %d\n",ans[1],ans[2]);
exit(0);
}
}
}
if(u!=rt && u!=ans[1] && smm*2==sz[u] && cnt){
printf("%d %d\n",u,ans[1]);exit(0);
}
if(sz[u]==smm)f[u]=u;
*/
if(u!=rt && sz[u]==smm* && f[u]){
ans[]=u;
ans[]=f[u];
}
if(sz[u]==smm)f[u]=u;
return;
}
int main(){
int i,j,u,v;
n=read();
for(i=;i<=n;i++){
u=read();v=read();
if(!u)rt=i;
else add_edge(u,i);
w[i]=v;smm+=v;
}
if(smm%){printf("-1\n");return ;}
smm/=;
DFS(rt);
if(ans[])printf("%d %d\n",ans[],ans[]);
else printf("-1\n");
return ;
}
C
D. Cartons of milk
排序+二分答案
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cstring>
#include<queue>
using namespace std;
const int mxn=;
int read(){
int x=,f=;char ch=getchar();
while(ch<'' || ch>''){if(ch=='-')f=-;ch=getchar();}
while(ch>='' && ch<=''){x=x*-''+ch;ch=getchar();}
return x*f;
}
struct node{
int w,id;
}a[mxn],b[mxn];
int cmp(const node a,const node b){
return a.w<b.w;
}
int n,m,k;
bool check(int lim){
int i,j;
int day=,now=;
for(i=,j=m-lim+;i<=n || j<=m; ){
if(i<=n && (j>m || a[i].w<=b[j].w)){
now++;
if(now>k){now-=k;day++;}
if(a[i].w<day)return ;
i++;
}
else{
now++;
if(now>k){now-=k;day++;}
if(b[j].w<day)return ;
j++;
}
}
return ;
}
int main(){
int i,j;
n=read();m=read();k=read();
for(i=;i<=n;i++){a[i].w=read();}
for(i=;i<=m;i++){b[i].w=read();b[i].id=i;}
sort(a+,a+n+,cmp);
sort(b+,b+m+,cmp);
int l=,r=m,ans=;
while(l<=r){
int mid=(l+r)>>;
if(check(mid)){
ans=mid;
l=mid+;
}
else r=mid-;
}
if(!ans)if(!check())ans=-;
printf("%d\n",ans);
for(i=m-ans+;i<=m;i++){
printf("%d ",b[i].id);
}
return ;
}
D
E. Change-free
起初有个脑洞,先每次都付纸币,然后贪心找不满度最大的日子“退流”。对正确性没有自信,悄悄看了看dalao们的代码,发现写法都是每次付硬币,然后贪心找不满度最小的日子改付纸币。
后一种好写,就写后一种咯
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cstring>
#include<queue>
using namespace std;
const int mxn=;
int read(){
int x=,f=;char ch=getchar();
while(ch<'' || ch>''){if(ch=='-')f=-;ch=getchar();}
while(ch>='' && ch<=''){x=x*-''+ch;ch=getchar();}
return x*f;
}
struct cmp{
int w,id;
friend bool operator < (const cmp a,const cmp b){
return a.w>b.w;
}
};
priority_queue<cmp> q;
bool note[mxn];
int n,m;
int c[mxn],w[mxn];
long long ans=;
void solve(){
int i,j;
for(i=;i<=n;i++){
int cost=c[i]%;if(!cost)continue;
int res=-cost;
// printf("res:%d\n",res*w[i]);
q.push((cmp){res*w[i],i});
m-=cost;
while(m<){
cmp tmp=q.top();q.pop();
ans+=tmp.w;
note[tmp.id]^=;
m+=;
}
}
return;
}
int main(){
int i,j;
n=read();m=read();
for(i=;i<=n;i++)c[i]=read();
for(j=;j<=n;j++)w[j]=read();
solve();
printf("%I64d\n",ans);
for(i=;i<=n;i++){
if(note[i])printf("%d %d\n",(c[i]+)/,);
else printf("%d %d\n",c[i]/,c[i]%);
}
return ;
}
E
Codeforces Round #398 (Div. 2) A-E的更多相关文章
- Codeforces Round #398 (Div. 2)
Codeforces Round #398 (Div. 2) A.Snacktower 模拟 我和官方题解的命名神相似...$has$ #include <iostream> #inclu ...
- Codeforces Round #398 (Div. 2) A. Snacktower 模拟
A. Snacktower 题目连接: http://codeforces.com/contest/767/problem/A Description According to an old lege ...
- Codeforces Round #398 (Div. 2) C. Garland —— DFS
题目链接:http://codeforces.com/contest/767/problem/C 题解:类似于提着一串葡萄,用剪刀剪两条藤,葡萄分成了三串.问怎样剪才能使三串葡萄的质量相等. 首先要做 ...
- Codeforces Round #398 (div.2)简要题解
这场cf时间特别好,周六下午,于是就打了打(谁叫我永远1800上不去div1) 比以前div2的题目更均衡了,没有太简单和太难的...好像B题难度高了很多,然后卡了很多人. 然后我最后做了四题,E题感 ...
- Codeforces Round #398 (Div. 2) A,B,C,D
A. Snacktower time limit per test 2 seconds memory limit per test 256 megabytes input standard input ...
- Codeforces Round #398 (Div. 2) A B C D 模拟 细节 dfs 贪心
A. Snacktower time limit per test 2 seconds memory limit per test 256 megabytes input standard input ...
- Codeforces Round #398 (Div. 2) B,C
B. The Queue time limit per test 1 second memory limit per test 256 megabytes input standard input o ...
- 【DFS】Codeforces Round #398 (Div. 2) C. Garland
设sum是所有灯泡的亮度之和 有两种情况: 一种是存在结点U和V,U是V的祖先,并且U的子树权值和为sum/3*2,且U不是根,且V的子树权值和为sum/3. 另一种是存在结点U和V,他们之间没有祖先 ...
- 【枚举】【贪心】 Codeforces Round #398 (Div. 2) B. The Queue
卡题意……妈的智障 一个人的服务时间完整包含在整个工作时间以内. 显然,如果有空档的时间,并且能再下班之前完结,那么直接输出即可,显然取最左侧的空档最优. 如果没有的话,就要考虑“挤掉”某个人,就是在 ...
- 【暴力】Codeforces Round #398 (Div. 2) A. Snacktower
题意不复述. 用个bool数组记录一下,如果某一天,当前剩下的最大的出现了的话,就输出一段. #include<cstdio> using namespace std; int n; bo ...
随机推荐
- SummerVocation_Leaning--java动态绑定(多态)
概念: 动态绑定:在执行期间(非编译期间)判断所引用的对象的实际类型,根据实际类型调用其相应的方法.如下例程序中,根据person对象的成员变量pet所引用的不同的实际类型调用相应的方法. 具体实现好 ...
- 1911: [Apio2010]特别行动队
Time Limit: 4 Sec Memory Limit: 64 MBSubmit: 5706 Solved: 2876[Submit][Status][Discuss] Descriptio ...
- String&StringBuffer&StringBuilder区别
String String类是final类故不可以继承,也就意味着String引用的字符串内容是不能被修改.String有两种实例化方式: (1)直接赋值(例中,String str = &q ...
- 查询集 QuerySet和管理器Manager
查询集 QuerySet 查询集,也称查询结果集.QuerySet,表示从数据库中获取的对象集合. 当调用如下过滤器方法时,Django会返回查询集(而不是简单的列表): all():返回所有数据. ...
- Computer HDU - 2196
Computer HDU - 2196 A school bought the first computer some time ago(so this computer's id is 1). Du ...
- python单元测试用例
demo1.py #!/usr/bin/python # encoding: utf-8 def hello(): print "i am in demo1" def add(x, ...
- Java的内存回收
一.java引用的种类 1.对象在内存中的状态 可达状态:当一个对象被创建后,有一个以上的引用变量指向它. 可恢复状态: 不可达状态:当对象的所有关联被切断,且系统调用所有对象的finalize方法依 ...
- Tomcat之web.xml中的<url-pattern>标签
关于web.xml配置中的<url-pattern> 标签<url-pattern> <url-pattern>是我们用Servlet做Web项目时需要经常配置的标 ...
- Java开发配置
http://www.runoob.com/java/java-environment-setup.html
- 使用WMI Filter 实现组策略的筛选!
今天接到一个客户的一个问题,提到需要分系统版本分发相应的MSI程序.比如简体版接受简体版的分发程序,繁体版接受繁体版的分发程序!这个建立组策略的不同版本分发本身不会太难,我们只需要建立两个不同组策略分 ...