Codeforces Round #404 (Div. 2) ABC
Anton's favourite geometric figures are regular polyhedrons. Note that there are five kinds of regular polyhedrons:
- Tetrahedron. Tetrahedron has 4 triangular faces.
- Cube. Cube has 6 square faces.
- Octahedron. Octahedron has 8 triangular faces.
- Dodecahedron. Dodecahedron has 12 pentagonal faces.
- Icosahedron. Icosahedron has 20 triangular faces.
All five kinds of polyhedrons are shown on the picture below:

Anton has a collection of n polyhedrons. One day he decided to know, how many faces his polyhedrons have in total. Help Anton and find this number!
The first line of the input contains a single integer n (1 ≤ n ≤ 200 000) — the number of polyhedrons in Anton's collection.
Each of the following n lines of the input contains a string si — the name of the i-th polyhedron in Anton's collection. The string can look like this:
- "Tetrahedron" (without quotes), if the i-th polyhedron in Anton's collection is a tetrahedron.
- "Cube" (without quotes), if the i-th polyhedron in Anton's collection is a cube.
- "Octahedron" (without quotes), if the i-th polyhedron in Anton's collection is an octahedron.
- "Dodecahedron" (without quotes), if the i-th polyhedron in Anton's collection is a dodecahedron.
- "Icosahedron" (without quotes), if the i-th polyhedron in Anton's collection is an icosahedron.
Output one number — the total number of faces in all the polyhedrons in Anton's collection.
#include <bits/stdc++.h>
using namespace std;
string str[] = {"Tetrahedron","Cube","Octahedron","Dodecahedron","Icosahedron"};
int num[] = {,,,,};
int main()
{
int n;
scanf("%d",&n);
int ans = ;
for(int i=;i<n;i++) {
string s;
cin>>s;
int flag = -;
for(int i=;i<;i++) {
if(str[i]==s) {
flag = i;
break;
}
}
if(flag!=-) {
ans += num[flag];
}
}
cout<<ans<<endl;
return ;
}
Anton likes to play chess. Also he likes to do programming. No wonder that he decided to attend chess classes and programming classes.
Anton has n variants when he will attend chess classes, i-th variant is given by a period of time (l1, i, r1, i). Also he has m variants when he will attend programming classes, i-th variant is given by a period of time (l2, i, r2, i).
Anton needs to choose exactly one of n possible periods of time when he will attend chess classes and exactly one of m possible periods of time when he will attend programming classes. He wants to have a rest between classes, so from all the possible pairs of the periods he wants to choose the one where the distance between the periods is maximal.
The distance between periods (l1, r1) and (l2, r2) is the minimal possible distance between a point in the first period and a point in the second period, that is the minimal possible |i - j|, where l1 ≤ i ≤ r1 and l2 ≤ j ≤ r2. In particular, when the periods intersect, the distance between them is 0.
Anton wants to know how much time his rest between the classes will last in the best case. Help Anton and find this number!
The first line of the input contains a single integer n (1 ≤ n ≤ 200 000) — the number of time periods when Anton can attend chess classes.
Each of the following n lines of the input contains two integers l1, i and r1, i (1 ≤ l1, i ≤ r1, i ≤ 109) — the i-th variant of a period of time when Anton can attend chess classes.
The following line of the input contains a single integer m (1 ≤ m ≤ 200 000) — the number of time periods when Anton can attend programming classes.
Each of the following m lines of the input contains two integers l2, i and r2, i (1 ≤ l2, i ≤ r2, i ≤ 109) — the i-th variant of a period of time when Anton can attend programming classes.
Output one integer — the maximal possible distance between time periods.
分析: 按照左右端点排序,找相隔最远的区间。
#include <bits/stdc++.h>
using namespace std;
struct Chess {
int l,r;
}chess[];
bool cmp1(Chess a,Chess b) {
return a.r < b.r;
}
bool cmp3(Chess a,Chess b) {
return a.l < b.l;
}
struct Prog {
int l,r;
}progs[];
bool cmp2(Prog a,Prog b) {
return a.l < b.l;
}
bool cmp4(Prog a,Prog b) {
return a.r < b.r;
}
int main()
{
int n,m;
scanf("%d",&n);
for(int i=;i<n;i++)
scanf("%d%d",&chess[i].l,&chess[i].r);
scanf("%d",&m);
for(int i=;i<m;i++)
scanf("%d%d",&progs[i].l,&progs[i].r);
sort(chess,chess+n,cmp1);
sort(progs,progs+m,cmp2);
int ans = ;
if(chess[].r<progs[m-].l)
ans = progs[m-].l - chess[].r;
if(progs[].r<chess[n-].l)
ans = max(ans,chess[n-].l-progs[].r);
sort(chess,chess+n,cmp3);
sort(progs,progs+m,cmp4);
if(chess[n-].l>progs[].r) {
ans = max(ans,chess[n-].l - progs[].r);
}
if(progs[m-].l>chess[].r) {
ans = max(ans,progs[m-].l - chess[].r);
}
cout<<ans<<endl;
return ;
}
Anton likes to listen to fairy tales, especially when Danik, Anton's best friend, tells them. Right now Danik tells Anton a fairy tale:
"Once upon a time, there lived an emperor. He was very rich and had much grain. One day he ordered to build a huge barn to put there all his grain. Best builders were building that barn for three days and three nights. But they overlooked and there remained a little hole in the barn, from which every day sparrows came through. Here flew a sparrow, took a grain and flew away..."
More formally, the following takes place in the fairy tale. At the beginning of the first day the barn with the capacity of n grains was full. Then, every day (starting with the first day) the following happens:
- m grains are brought to the barn. If m grains doesn't fit to the barn, the barn becomes full and the grains that doesn't fit are brought back (in this problem we can assume that the grains that doesn't fit to the barn are not taken into account).
- Sparrows come and eat grain. In the i-th day i sparrows come, that is on the first day one sparrow come, on the second day two sparrows come and so on. Every sparrow eats one grain. If the barn is empty, a sparrow eats nothing.
Anton is tired of listening how Danik describes every sparrow that eats grain from the barn. Anton doesn't know when the fairy tale ends, so he asked you to determine, by the end of which day the barn will become empty for the first time. Help Anton and write a program that will determine the number of that day!
The only line of the input contains two integers n and m (1 ≤ n, m ≤ 1018) — the capacity of the barn and the number of grains that are brought every day.
Output one integer — the number of the day when the barn will become empty for the first time. Days are numbered starting with one.
分析:
当每次供给很大的时候,第二天总能将它补满,那么只能是,一天之内就将食物全部吃完。也就是第 n 天。
否则的话:
前 m 天,每次吃走一些,又补满,这样持续 m 天,m 天后,粮食才开始减少,每天减少 1 ,2,3,
也就是:

m + (1+mid)*mid/2 >=n 的时候就吃完了,注意这个 mid 时间,是 m 天之后的,那个时候才开始减少。也就是说,结果是 mid + m。
注意,二分的时候, 右区间的范围很大。
#include <bits/stdc++.h> using namespace std; int main()
{
long long n,m;
cin>>n>>m; if(m>=n)
cout<<n<<endl;
else {
long long l = ,r = ((long long)<<); while(l<r) { long long mid = l + (r - l)/;
if(m + (mid+)*mid/ < n)
l = mid+ ;
else r = mid; }
cout<<m+l<<endl;
} return ;
}
Codeforces Round #404 (Div. 2) ABC的更多相关文章
- Codeforces Round #404 (Div. 2) C 二分查找
Codeforces Round #404 (Div. 2) 题意:对于 n and m (1 ≤ n, m ≤ 10^18) 找到 1) [n<= m] cout<<n; 2) ...
- Codeforces Round #366 (Div. 2) ABC
Codeforces Round #366 (Div. 2) A I hate that I love that I hate it水题 #I hate that I love that I hate ...
- Codeforces Round #247 (Div. 2) ABC
Codeforces Round #247 (Div. 2) http://codeforces.com/contest/431 代码均已投放:https://github.com/illuz/Wa ...
- Codeforces Round #404 (Div. 2) DE
昨晚玩游戏竟然不小心错过了CF..我是有多浪啊. 今天总算趁着下课时间补了,感觉最后两题还是挺有意思的,写个题解. D: 题目大意: 给出一个括号序列,问有多少个子序列 是k个'(' + k个')' ...
- Codeforces Round #404 (Div. 2) D. Anton and School - 2 数学
D. Anton and School - 2 题目连接: http://codeforces.com/contest/785/problem/D Description As you probabl ...
- Codeforces Round #404 (Div. 2) A,B,C,D,E 暴力,暴力,二分,范德蒙恒等式,树状数组+分块
题目链接:http://codeforces.com/contest/785 A. Anton and Polyhedrons time limit per test 2 seconds memory ...
- Codeforces Round #404 (Div. 2)(A.水,暴力,B,排序,贪心)
A. Anton and Polyhedrons time limit per test:2 seconds memory limit per test:256 megabytes input:sta ...
- Codeforces Round #404 (Div. 2)A,B,C
A. Anton and Polyhedrons 题目链接:http://codeforces.com/contest/785/problem/A 智障水题 实现代码: #include<bit ...
- Codeforces Round #404 (Div. 2) C. Anton and Fairy Tale 二分
C. Anton and Fairy Tale 题目连接: http://codeforces.com/contest/785/problem/C Description Anton likes to ...
随机推荐
- scp —— 服务器之间互传文件
scp 可以在 2个 linux 主机间复制文件: 从 本地 复制到 远程 * 复制文件: 举例子: scp /home/space/music/.mp3 root@192.168.0.1 ...
- 使用springmvc时处理404的方法
使用springmvc时处理404的方法 来源: https://www.cnblogs.com/handsome-man/p/5519439.html,再次申明不是我原创的,尊重原创 如何定义404 ...
- python_文件操作代码实例
"""提示:代码中的内容均被注释,请参考,切勿照搬""" 1 #文件的打开和关闭 ''' 文件对象 = open('文件名','使用方式') ...
- Boxes in a Line UVA - 12657 (双向链表)
题目链接:https://vjudge.net/problem/UVA-12657 题目大意:输入n,m 代表有n个盒子 每个盒子最开始按1~n排成一行 m个操作, 1 x y :把盒子x放到y ...
- leetcode 197. Rising Temperature sql_Date用法
https://leetcode.com/problems/rising-temperature/description/ 题目需要选出今天比昨天气温高的ID 用join,默认是inner join需 ...
- caffe学习资料
1.利用Caffe做回归(regression) http://www.cnblogs.com/frombeijingwithlove/p/5314042.html
- Windows下Redis数据库管理工具(redis-desktop-manager)安装与配置(图文详解)
Redis Desktop Manager安装 Redis Desktop Manager直接下载安装就行非常简单.下载地址: 官网下载:https://redisdesktop.com/downlo ...
- 用spring的 InitializingBean 的 afterPropertiesSet 来初始化
void afterPropertiesSet() throws Exception; 这个方法将在所有的属性被初始化后调用. 但是会在init前调用. 但是主要的是如果是延迟加载的话,则马上执行. ...
- python3.4中自定义wsgi函数,make_server函数报错问题
别的不多说,先上代码 #coding:utf-8 from wsgiref.simple_server import make_server def RunServer(environ, start_ ...
- jq学习总结之方法
三.方法 1.length 2.index()3.get() reverse()4.not()5.filter()6.find()7.each()8.addBack()9.attr()10.toggl ...