Codeforces Round #398 (Div. 2) B,C
1 second
256 megabytes
standard input
standard output
Finally! Vasya have come of age and that means he can finally get a passport! To do it, he needs to visit the passport office, but it's not that simple. There's only one receptionist at the passport office and people can queue up long before it actually opens. Vasya wants to visit the passport office tomorrow.
He knows that the receptionist starts working after ts minutes have passed after midnight and closes after tf minutes have passed after midnight (so that (tf - 1) is the last minute when the receptionist is still working). The receptionist spends exactly t minutes on each person in the queue. If the receptionist would stop working within t minutes, he stops serving visitors (other than the one he already serves).
Vasya also knows that exactly n visitors would come tomorrow. For each visitor Vasya knows the point of time when he would come to the passport office. Each visitor queues up and doesn't leave until he was served. If the receptionist is free when a visitor comes (in particular, if the previous visitor was just served and the queue is empty), the receptionist begins to serve the newcomer immediately.
"Reception 1"
For each visitor, the point of time when he would come to the passport office is positive. Vasya can come to the office at the time zero (that is, at midnight) if he needs so, but he can come to the office only at integer points of time. If Vasya arrives at the passport office at the same time with several other visitors, he yields to them and stand in the queue after the last of them.
Vasya wants to come at such point of time that he will be served by the receptionist, and he would spend the minimum possible time in the queue. Help him!
The first line contains three integers: the point of time when the receptionist begins to work ts, the point of time when the receptionist stops working tf and the time the receptionist spends on each visitor t. The second line contains one integer n — the amount of visitors (0 ≤ n ≤ 100 000). The third line contains positive integers in non-decreasing order — the points of time when the visitors arrive to the passport office.
All times are set in minutes and do not exceed 1012; it is guaranteed that ts < tf. It is also guaranteed that Vasya can arrive at the passport office at such a point of time that he would be served by the receptionist.
Print single non-negative integer — the point of time when Vasya should arrive at the passport office. If Vasya arrives at the passport office at the same time with several other visitors, he yields to them and queues up the last. If there are many answers, you can print any of them.
10 15 2
2
10 13
12
8 17 3
4
3 4 5 8
2
In the first example the first visitor comes exactly at the point of time when the receptionist begins to work, and he is served for two minutes. At 12 minutes after the midnight the receptionist stops serving the first visitor, and if Vasya arrives at this moment, he will be served immediately, because the next visitor would only come at 13 minutes after midnight.
In the second example, Vasya has to come before anyone else to be served.
题意:
服务员工作时间是ts~tf,每服务一个人需要t时间,已知n个人来排队等待服务的时间,问我什么时候去才能使我的排队时间最少,如果我到达的时间和某一个人相同就会排到最后
//用tim记录服务员下一次可以接受服务的时间,每输入一个人,最好的情况是他来的时间晚于
//服务员下次服务的时间,这样我可以直接去接受服务。其次是如果他前一时间没有人来,
//我去到他前面等一会接受服务。
#include<bits/stdc++.h>
using namespace std;
long long ts,tf,t,n;
int main()
{
cin>>ts>>tf>>t>>n;
long long tim=ts,x,y,pre=-,ans,maxt=1e12+;
for(int i=;i<=n;i++){
cin>>x;
if(tim>tf||maxt==) continue;
y=x-;
if(y>=&&x<=tim&&y>pre){
if(tim-x+<maxt) {ans=y;maxt=tim-x+;}
}
if(x>tim){
ans=tim;maxt=;
}
tim+=t;
pre=x;
}
if(tim+t<=tf&&maxt!=) ans=tim;//如果最后还有剩余的服务时间
cout<<ans<<endl;
return ;
}
2 seconds
256 megabytes
standard input
standard output
Once at New Year Dima had a dream in which he was presented a fairy garland. A garland is a set of lamps, some pairs of which are connected by wires. Dima remembered that each two lamps in the garland were connected directly or indirectly via some wires. Furthermore, the number of wires was exactly one less than the number of lamps.
There was something unusual about the garland. Each lamp had its own brightness which depended on the temperature of the lamp. Temperatures could be positive, negative or zero. Dima has two friends, so he decided to share the garland with them. He wants to cut two different wires so that the garland breaks up into three parts. Each part of the garland should shine equally, i. e. the sums of lamps' temperatures should be equal in each of the parts. Of course, each of the parts should be non-empty, i. e. each part should contain at least one lamp.
Help Dima to find a suitable way to cut the garland, or determine that this is impossible.
While examining the garland, Dima lifted it up holding by one of the lamps. Thus, each of the lamps, except the one he is holding by, is now hanging on some wire. So, you should print two lamp ids as the answer which denote that Dima should cut the wires these lamps are hanging on. Of course, the lamp Dima is holding the garland by can't be included in the answer.
The first line contains single integer n (3 ≤ n ≤ 106) — the number of lamps in the garland.
Then n lines follow. The i-th of them contain the information about the i-th lamp: the number lamp ai, it is hanging on (and 0, if is there is no such lamp), and its temperature ti ( - 100 ≤ ti ≤ 100). The lamps are numbered from 1 to n.
If there is no solution, print -1.
Otherwise print two integers — the indexes of the lamps which mean Dima should cut the wires they are hanging on. If there are multiple answers, print any of them.
6
2 4
0 5
4 2
2 1
1 1
4 2
1 4
6
2 4
0 6
4 2
2 1
1 1
4 2
-1
The garland and cuts scheme for the first example:
//算出每一棵子树包含的权值付给根节点,当某一根节点值是sum/3时记录相关边,并去掉这颗子树。
//题目的特殊输入,边的编号就是改边作为儿子节点的编号。
#include<bits/stdc++.h>
using namespace std;
int n,cnt[],s[];
int a,b,sum=,nu;
vector<int>p[];
int dfs(int x,int fx){
int len=p[x].size();
for(int i=;i<len;i++)
cnt[x]+=dfs(p[x][i],x);
if(cnt[x]==sum/&&fx!=&&nu<=) {s[++nu]=x;return ;}
return cnt[x];
}
int main()
{
scanf("%d",&n);
nu=;
for(int i=;i<=n;i++){
scanf("%d%d",&a,&b);
cnt[i]=b;
sum+=b;
p[a].push_back(i);
}
if(sum%) printf("-1\n");
else{
cnt[]=dfs(p[][],);
if(nu<) printf("-1\n");
else printf("%d %d\n",s[],s[]);
}
return ;
}
Codeforces Round #398 (Div. 2) B,C的更多相关文章
- 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 ...
- 【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 ...
随机推荐
- 使用Python客户端(redis-py)连接Redis--华为云DCS for Redis使用经验
使用Python连接Redis,需要先安装Python以及redis-py,以CentOS为例,介绍redis-py的客户端环境搭建. 第0步:准备工作 华为云上购买1台弹性云服务器ECS(我选了Ce ...
- hibernate 异常a different object with the same identifier value was already associated with the session
在使用hibernate的时候发现了一个问题,记录一下解决方案. 前提开启了事务和事务间并无commit,进行两次save,第二次的时候爆出下面的异常a different object with t ...
- Ext JS 6学习文档-第7章-图表
Ext JS 6学习文档-第7章-图表 使用图表 本章中将探索在 ExtJS 中使用不同类型的图表并使用一个名为费用分析的示例项目结束本章所学.以下是将要所学的内容: 图表类型 条形图 和 柱形图 图 ...
- java知乎爬虫
好久没写博客了,前阵子项目忙着上线,现在有点空闲,就把最近写的一个爬虫和大家分享下,统计结果放在了自己买的阿里云服务器上(点此查看效果),效果如下: 程序是在工作之余写的,用了java 的webmgi ...
- OSG数学基础:坐标系变换
三维实体对象需要经过一系列的坐标变换才能正确.真实地显示在屏幕上.在一个场景中,当读者对场景中的物体进行各种变换及相关操作时,坐标系变换是非常频繁的. 坐标系变换通常包括:世界坐标系-物体坐标系变换. ...
- 《学习OpenCV》课后习题解答1
题目:(P104) 下面这个练习是帮助掌握矩阵类型.创造一个三通道二维矩阵,字节类型,大小为100*100,并设置所有数值为0. a.在矩阵中使用cvCircle( CvArr* img, CvPoi ...
- 使用tc来控制网络流量
https://blog.csdn.net/qinyushuang/article/details/46611709 tc实际操控网络的流量 解释网络tc的架构,从架构上分析tc,与netfilter ...
- Oracle查询字段中有空格的数据
一.问题说明 最近在给某个用户下的表批量添加注释时,在程序中将注释名用trim()过滤一遍就可以了,但是在程序执行成功后怎么检测添加的注释名是否有空格存在呢? 二.解决方法 1.SELECT * FR ...
- arp hook
最近疯狂的研究Linux的种种功能,也颇有心得,这里讲述一下Linux下的Net的Hook,使用net的Hook可以实现很多很多非常底层的功能,比如过滤报文,做防火墙,做代理等等. Now,Let's ...
- [C/C++] C++模板定义格式
函数模板的格式: template <class 形参名,class 形参名,......> 返回类型 函数名(参数列表) { //函数体 } 类模板的格式为: template<c ...