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 ...
随机推荐
- 学习笔记(七): Logistic Regression
目录 Calculating a Probability Model Training 1.Loss function for Logistic Regression 2.Regularization ...
- pycharm clion rider 注册
JetBrains 公司出品的pycharm clion rider 专业版本都需要注册才能运行,这里有个免费注册方法: JetBrains授权服务器2017.10.7授权方法:激活时选择Licens ...
- 14.2-ELK 经典用法—企业自定义日志收集切割和mysql模块
本文收录在Linux运维企业架构实战系列 一.收集切割公司自定义的日志 很多公司的日志并不是和服务默认的日志格式一致,因此,就需要我们来进行切割了. 1.需切割的日志示例 2018-02-24 11: ...
- LeetCode946-验证栈序列
问题:验证栈序列 给定 pushed 和 popped 两个序列,只有当它们可能是在最初空栈上进行的推入 push 和弹出 pop 操作序列的结果时,返回 true:否则,返回 false . 示例 ...
- PAT Basic 1085
1085 PAT单位排行 每次 PAT 考试结束后,考试中心都会发布一个考生单位排行榜.本题就请你实现这个功能. 输入格式: 输入第一行给出一个正整数 N(≤105),即考生人数.随后 N 行, ...
- 笔记-python tutorial-9.classes
笔记-python tutorial-9.classes 1. Classes 1.1. scopes and namespaces namespace: A namespace is ...
- 定时任务之crond服务
计划任务分为一次性计划任务与长期性计划任务 一次性计划任务:今天11:25执行重启网卡操作,执行结束 即任务消失 一次性计划任务格式: 创建:"at 时间" #默认采用的是交互式 ...
- 裸奔着造房子——对政府禁止采购Win8系统的一些看法
前段时间有消息称政府招标的项目将禁止使用Win8系统,原因是Win8系统的安全架构将有利于暴露敏感信息给微软,而微软的老子是美利坚,老子想要知道什么,儿子当然不敢不从.因此Win8也被打入冷宫,微软多 ...
- OpenCV学习笔记(四) Mat的简单操作
转自:OpenCV Tutorial: core 模块. 核心功能 改变图像对比度和亮度:convertTo 可以把 看成源图像像素,把 看成输出图像像素.这样一来,调整亮度和对比度的方法可表示为 ...
- 线性回归 python小样例
线性回归优点:结果易于理解,计算上不复杂缺点:对非线性的数据拟合不好适用数据类型:数值型和标称型数据horse=0.0015*annualSalary-0.99*hoursListeningToPul ...