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 ...
随机推荐
- python模块之beautifulSoup
1. Beautiful Soup的简单介绍 Beautiful Soup是python的一个库,主要的功能是从网页抓取数据,并对数据进行分析.官方解释为:Beautiful Soup提供一些简单的. ...
- OpenCV属性页配置问题~
详细的OpenCV属性页的安装流程,参考这个网站:http://m.bubuko.com/infodetail-793518.html 运行例子时候,如果遇到这个问题,可能配置环境时候出现问题了. 此 ...
- Zabbix sql注入漏洞脚本执行反弹shell
exp检测是否存在SQL注入漏洞root@ubuntu:~# python zabbix.py http://ip:9090/+------------------------------------ ...
- my02_Atlas mysql5.7安装配置
软件环境:centos7.3,glib-2.49,lua5.1,Atlas2.2.1,mysql5.7 依赖包安装******************************************* ...
- java——volatile的可见性不能保证线程安全
volatile: 1.保证变量对所有线程的可见性(但是由于java里面的运算并非原子操作,导致volatile变量的运算在并发下一样是不安全的) 用代码试过,确实是这样的,原因:有可能同时多个thr ...
- SQL SEVER 数据库日志(Log)文件增长过快的处理
SQL SERVER 2016数据库,50GB+的数据.有大量的增删和插入操作,数据库log文件变得异常的大,而且增长速度特别的快.周五log文件20GB,周一上班就成了200+GB了 因为数据库恢复 ...
- my.宠物升级79级
1.蚌仙子 74级半不到的时候,吃 月华露(500000经验的那种) 吃3个 正好 79级半 我记得 之前 是升满75级 再吃月华露 到79级的时候 经验溢出了.不突破还好,突破的话 宠物就升级了 ...
- C# 反射(Reflection)
反射主要用于在程序运行期间动态解析相关类的类名,命名空间,属性,方法并进行相应操作,以下通过两个简单的例子进行了说明: 示例1:调用程序集内部方法,运行时动态获取相关类的信息,包括类名,命名空间等信息 ...
- ubuntu 16.04 安装genymotion
以ubuntu 16.04 64bit 系统为例: 1. 下载 通过https://www.genymotion.com/download/ 下载自己操作系统版本的可执行文件( ...
- Murano Weekly Meeting 2015.10.13
Meeting time: 2015.October.13th 1:00~2:00 Chairperson: Serg Melikyan, PTL from Mirantis Meeting sum ...