分数史上新低

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

  1. Codeforces Round #398 (Div. 2)

    Codeforces Round #398 (Div. 2) A.Snacktower 模拟 我和官方题解的命名神相似...$has$ #include <iostream> #inclu ...

  2. Codeforces Round #398 (Div. 2) A. Snacktower 模拟

    A. Snacktower 题目连接: http://codeforces.com/contest/767/problem/A Description According to an old lege ...

  3. Codeforces Round #398 (Div. 2) C. Garland —— DFS

    题目链接:http://codeforces.com/contest/767/problem/C 题解:类似于提着一串葡萄,用剪刀剪两条藤,葡萄分成了三串.问怎样剪才能使三串葡萄的质量相等. 首先要做 ...

  4. Codeforces Round #398 (div.2)简要题解

    这场cf时间特别好,周六下午,于是就打了打(谁叫我永远1800上不去div1) 比以前div2的题目更均衡了,没有太简单和太难的...好像B题难度高了很多,然后卡了很多人. 然后我最后做了四题,E题感 ...

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

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

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

  8. 【DFS】Codeforces Round #398 (Div. 2) C. Garland

    设sum是所有灯泡的亮度之和 有两种情况: 一种是存在结点U和V,U是V的祖先,并且U的子树权值和为sum/3*2,且U不是根,且V的子树权值和为sum/3. 另一种是存在结点U和V,他们之间没有祖先 ...

  9. 【枚举】【贪心】 Codeforces Round #398 (Div. 2) B. The Queue

    卡题意……妈的智障 一个人的服务时间完整包含在整个工作时间以内. 显然,如果有空档的时间,并且能再下班之前完结,那么直接输出即可,显然取最左侧的空档最优. 如果没有的话,就要考虑“挤掉”某个人,就是在 ...

  10. 【暴力】Codeforces Round #398 (Div. 2) A. Snacktower

    题意不复述. 用个bool数组记录一下,如果某一天,当前剩下的最大的出现了的话,就输出一段. #include<cstdio> using namespace std; int n; bo ...

随机推荐

  1. 2018.10.30 NOIp模拟赛 T1 改造二叉树

    [题目描述] 小Y在学树论时看到了有关二叉树的介绍:在计算机科学中,二叉树是每个结点最多有两个子结点的有序树.通常子结点被称作“左孩子”和“右孩子”.二叉树被用作二叉搜索树和二叉堆.随后他又和他人讨论 ...

  2. python 输入英语单词,查看汉语意思

    # -*- coding:utf-8 -*- import urllib2 import lxml.html as HTML def get_wordmean(): url = 'http://www ...

  3. JZOJ 5838. 旅游路线 最大子段和

    5838. 旅游路线 Time Limits: 1000 ms  Memory Limits: 131072 KB  Detailed Limits   Goto ProblemSet Descrip ...

  4. 本地Navicat连接虚拟机MySQL

    安装完MySQL后,使用mysql命令进去,然后执行以下命令 grant all privileges on hive_metadata.* to 'hive'@'%' identified by ' ...

  5. 关于Linux系统下zookeeper集群的搭建

    1.集群概述 1.1什么是集群 1.1.1集群概念 集群是一种计算机系统, 它通过一组松散集成的计算机软件和/或硬件连接起来高度紧密地协作完成计算工作.在某种意义上,他们可以被看作是一台计算机.集群系 ...

  6. 树莓派下ubuntu-mate中ssh服务的安装与开机后自启动

    ssh程序分为客户端程序openssh-client和服务端程序openssh-server. 如果需要ssh登陆到别的电脑,需要安装openssh-client,该程序ubuntu是默认安装的.而如 ...

  7. Spring核心技术(十四)——ApplicationContext的额外功能

    在前文的介绍中我们知道,org.springframework.beans.factory包提供了一些基本的功能来管理和控制Bean,甚至通过编程的方式来实现.org.springframework. ...

  8. HDFS上传文件

    1.client端向namenode请求上传文件,查看文件是否存在,是否有权限往hdfs写入 2.如果文件不存在,权限OK就根据副本数N(例如2个),根据网络拓扑选择N个离client端最近的data ...

  9. socketCluster 使用

    <html> <head> <title>test</title> <script src="https://cdn.bootcss.c ...

  10. Core Java的那点事儿之ArrayList

    Core Java的那点事儿之ArrayList 万丈高楼平地起,Java基础要拿起.今天就从我看的Core Java里找了些小基础点来分享一下. 首先隆重介绍一下专业级龙套演员---Employee ...