CODEFORCES 270C Magical Boxes <<小箱子装大箱子>>
2016-07-06 07:25
483 查看
题意:小箱子可以装在大箱子里,给出各种箱子的边长及个数,求把所有箱子装入一个箱子,那么此箱子最小边长是2^i,输出i
样例:
Input
Output
Input
Output
Input
Output
样例:
Input
2 0 3 1 5
Output
3
Input
1 0 4
Output
1
Input
2 1 10 2 2
Output
3
#include <iostream> #include <cstdio> #define LL long long #include <cstdlib> #include <map> #define MAXN 200005 #include <algorithm> #include <cmath> using namespace std; struct Edge { long long ki; long long ai; bool operator<(const Edge& ee) { return ki > ee.ki; } }e[100005]; int main() { long n,i; long long index,ans; while(cin>> n) { index = -1; for(i=0; i<n; i++) { cin>>e[i].ki>>e[i].ai; if(index < e[i].ki) index = e[i].ki; } sort(e,e+n); ans = index + 1; //cout << "ans = " << ans <<endl; for(int i=0; i<n; i++) { index = ans - e[i].ki; if(index>30) continue; index = pow(4.0,index); while(e[i].ai>index) { index*=4; ans++; //cout << "index = " << index << endl; } } cout << ans <<endl; } return 0; }
相关文章推荐
- C# Refactorings VS插件
- Binary Tree Longest Consequence
- 学习ASP.NET Core,你必须了解无处不在的“依赖注入”
- .NET Core应用类型(Portable apps & Self-contained apps)
- Merge k Sorted Lists
- CODEFORCES 270B Multithreading <<新闻持续更新>>
- 封装JavaBean对象
- Smallest rectangle Enclose Black Pixels
- NoSql入门和概述
- C++学习指南
- IntelliJ IDEA快捷键大全(图片)
- 3 Sum
- 3497. 水仙花数
- Swift编程规范之 Naming
- N-Queens | & N-Queens II
- leetcode-100. Same Tree c++
- 1561. PRIME
- Java中线程入门
- 1510. Mispelling
- MySQL: Tree-Hierarchical query