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. ajaxfileupload.js异步上传

    转载:https://www.cnblogs.com/labimeilexin/p/6742647.html jQuery插件之ajaxFileUpload     ajaxFileUpload.js ...

  2. centeros 6.5 网络设置

    vi  /etc/sysconfig/network-script/ifcfg-eth0 关键点  nat设置中的网关,dhcp设置中起始网络地址跟结束ip地址,选择其中范围的一个即可 service ...

  3. NIOGoodDemo

    Java NIO是在jdk1.4开始使用的,它既可以说成“新I/O”,也可以说成非阻塞式I/O.下面是java NIO的工作原理: 1. 由一个专门的线程来处理所有的 IO 事件,并负责分发. 2. ...

  4. Linux下安装&运行Jmeter程序

    Jmeter在linux系统中运行需要安装jdk和Jmeter两个软件: 1.安装JDK 先检查系统是否有安装jdk,在linux中执行如下命令:java -version  如果返回版本信息,说明系 ...

  5. git知识点总结

    集中式版本控制系统,版本库是集中存放在中央服务器的,而干活的时候,用的都是自己的电脑,所以要先从中央服务器取得最新的版本,然后开始干活,干完活了,再把自己的活推送给中央服务器.集中式版本控制系统最大的 ...

  6. is 和 == 区别

    == 和 is 的区别 == 比较 比较的是两个值 适用于 列表​a = '[1:2]'b = '[1:2]'print(a == b) #True​​​​ 字典a = '{1,2,3}'b = '{ ...

  7. SuperSpider(简书爬虫JAVA版)

    * 建站数据SuperSpider(简书)* 本项目目的:* 为练习web开发提供相关的数据:* 主要数据包括:* 简书热门专题模块信息.对应模块下的热门文章.* 文章的详细信息.作者信息.* 评论区 ...

  8. mongodb3集群搭建

    三台服务器:先设置hosts 10.0.0.231 node1 10.0.0.232 node2 10.0.0.233 node3 1:下载 mongodb-linux-x86_64-rhel70-3 ...

  9. Linux 下 zip 文件解压乱码解决方案,ubuntu16.10亲测可用

    文章来源: https://www.zhihu.com/question/20523036 今天邮件中收到了一个压缩文件,解压后却是乱码,从网上也找了几个方法,目前这个方法还是比较可靠的,如下所示: ...

  10. oracle 找回被覆盖的存储过程

    登录到sys账户下 1.TO_TIMESTAMP('2014-05-04 14:33:00', 'YYYY-MM-DD HH24:MI:SS') 删除前的日期 2.owner 表空调 3.Name   ...