A. Anton and Polyhedrons

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!

Input

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

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 ;
}
B. Anton and Classes

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!

Input

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

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 ;
}
C. Anton and Fairy Tale

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!

Input

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

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的更多相关文章

  1. 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) ...

  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 ...

  3. Codeforces Round #247 (Div. 2) ABC

    Codeforces Round #247 (Div. 2) http://codeforces.com/contest/431  代码均已投放:https://github.com/illuz/Wa ...

  4. Codeforces Round #404 (Div. 2) DE

    昨晚玩游戏竟然不小心错过了CF..我是有多浪啊. 今天总算趁着下课时间补了,感觉最后两题还是挺有意思的,写个题解. D: 题目大意: 给出一个括号序列,问有多少个子序列 是k个'(' + k个')' ...

  5. 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 ...

  6. 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 ...

  7. 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 ...

  8. Codeforces Round #404 (Div. 2)A,B,C

    A. Anton and Polyhedrons 题目链接:http://codeforces.com/contest/785/problem/A 智障水题 实现代码: #include<bit ...

  9. 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 ...

随机推荐

  1. Problem06 求最大公约数及最小公倍数

    题目:输入两个正整数m和n,求其最大公约数(m,n)和最小公倍数[m,n]. 程序分析:利用辗转相除法. 利用辗除法:用较大数除以较小数,再用出现的余数(第一余数)去除除数, 再用出现的余数(第二余数 ...

  2. 【ACM】N皇后问题

    N皇后问题 #include <iostream> #include <cmath> using namespace std; ; //判断当前位置的皇后加入是否成立 bool ...

  3. linux在命令符界面如何浏览网页

    1.介绍 w3m是个开放源代码的命令行下面的网页浏览器. 它支持表格.框架.SSL连线.颜色.如果是在适当的terminal上,甚至还支持"inline image". 这个软件通 ...

  4. 01-消息中间件概述和ActiveMq入门

    1.mq解决的问题 系统异步处理 应用解耦 流量削峰 日志处理 消息通信 2.消息中间件的2中模型 2.1 Point-to-Point(P2P) / 点对点 / 类比:送快递 特点: + 一个消费生 ...

  5. pyplot

    错误: 执行 import matplotlib.pyplot 报错 ImportError: No module named _tkinter, please install the python- ...

  6. IO流等学习笔记

    1.为什么日期的开始是从1970年0101开始记录,计算机的日期记录是现在的时间距1970年的时间,可正可负.? 2.引用类型默认都为null,基本数据类型为0,除基本数据类型外所有的都为引用数据类型 ...

  7. web service, wcf, wcf rest, web api之间的区别

    在.NET Framework中,有很多种技术可以创建基于http协议的服务,譬如说web service, wcf,wcf rest和web api等等.网上有很多的文章教我们如何开发.使用这几种技 ...

  8. 【转】Android实现伸缩弹力分布菜单效果

    本文介绍下在Android中实现伸缩弹力分布菜单效果.关于这种菜单效果在IPhone中比较常见,效果比较酷.那么在Android中实现只是一种简单的模仿. 这两天无意间看到一园友的博文实现Path2. ...

  9. AngularJS directive 动态 template

    app.directive('testwindow', function() { return { restrict : 'E', template: '<ng-include src=&quo ...

  10. C#中 计时器用法 运行时间

    有时候我们会需要计算某段代码运行的时间 比如一个sql查询,记录一段代码所花费的时间等等代码如下: System.Diagnostics.Stopwatch watch = new System.Di ...