分数史上新低

开场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. PyCharm 2018.1 软件汉化

    下载汉化包 链接: https://pan.baidu.com/s/1buLFINImW_3cNzP8HsB4cA 密码: fqpu 安装汉化包 找到pycharm安装目录 直接把刚刚下载的汉化包复制 ...

  2. 关于springboot配置文件的另类读取方法

    一.背景故事   前阵子我接手了公司另外一个同事手里的项目,项目是用的springboot 写的,但是比较坑的就是这个项目写的有点不伦不类.虽然是用的springboot,但由于他是拿了一堆代码拼凑起 ...

  3. JZOJ 5456. 【NOIP2017提高A组冲刺11.6】奇怪的队列

    5456. [NOIP2017提高A组冲刺11.6]奇怪的队列 (File IO): input:queue.in output:queue.out Time Limits: 1000 ms  Mem ...

  4. 数据分析处理库Pandas——概述

    导入Pandas库 创建DataFrame结构 读取.csv文件 titanic_train.csv文件:https://files.cnblogs.com/files/gloria-zhang/ti ...

  5. 使用Vue CLI3开发多页面应用

    一.安装vue-cli3 1.如果你已经全局安装了旧版本的 vue-cli(1.x 或 2.x),你需要先通过 npm uninstall vue-cli -g 或 yarn global remov ...

  6. 关于前后端日期处理 开发注意事项 jquery.tmpl()函数的使用

    1当后端将日期传到前段的时候 我们通常会需要将日期转为制定格式 除了平常我们使用的前段插件将日期转好 spring @datetimeFormat 注解 这些形式外 我们还可以在实体里通过get方法进 ...

  7. 1 - JVM随笔分类(java虚拟机的内存区域分配(一个不断记录和推翻以及再记录的一个过程))

    java虚拟机的内存区域分配   在JVM运行时,类加载器ClassLoader在加载到类的字节码后,交由jvm的执行引擎处理, 执行过程中需要空间来存储数据(类似于Cpu及主存),此时的这段空间的分 ...

  8. Python对文本文件的简单操作(一)

    工作背景 性能测试工程师,主要测试工具--loadrunner,主要是接口测试. 实现功能 loadrunner对报文格式的转换存在问题,部分报文无法转换,故使用Python编写脚本自动将soap协议 ...

  9. Python+Selenium练习篇之4-利用link text定位元素

    本文介绍如何通过link text 来定位页面元素,我们打开网页,一些可以点击的链接跳转上面的文字,就是link text,用百度首页举例来看: 在上面图中,这一排上面的文字都是link text,例 ...

  10. Linux下测试SSD固态硬盘写入速度

    最近买了一个256GB的SSD固态硬盘,想测试一下写入速度,于是如下操作. 部分代码: gettimeofday(&start, NULL); int fd = open("test ...