LA 3971 二分
来源:互联网 发布:意大利留学知乎 编辑:程序博客网 时间:2024/05/10 09:47
直接二分搜品质因子
AC代码如下:
#include <cstring>#include <cstdio>#include <algorithm>#include <iostream>#include <map>#include <string>#include <vector>using namespace std;#define MAX 0x3f3f3f3fint N, B;map<string,int> id;vector<int> price[1100], para[1100];int cnt, L, R;bool judge( int M ){ int sum = 0; for( int i = 1; i <= cnt; i++ ){ int temp = MAX; for( int j = 0; j < price[i].size(); j++ ){ if( para[i][j] >= M ){ temp = min( temp, price[i][j] ); } } sum += temp; if( sum > B ){ return false; } } return true;}int main(){ int T; scanf( "%d", &T ); while( T-- ){ scanf( "%d%d", &N, &B ); id.clear(); for( int i = 0; i < 1100; i++ ){ price[i].clear(); para[i].clear(); } cnt = 0; R = 0; for( int i = 0; i < N; i++ ){ string temp1, temp2; int temp3, temp4; cin >> temp1 >> temp2 >> temp3 >> temp4; R = max( R, temp4 ); if( id.find( temp1 ) != id.end() ){ price[id[temp1]].push_back( temp3 ); para[id[temp1]].push_back( temp4 ); }else{ id[temp1] = ++cnt; price[id[temp1]].push_back( temp3 ); para[id[temp1]].push_back( temp4 ); } } L = 0; while( L < R ){ int M = L + ( R - L + 1 ) / 2; if( judge( M ) ){ L = M; }else{ R = M - 1; } } cout << L << endl; } return 0;}
0 0
- LA 3971 Assemble / 二分
- LA 3971 二分
- UVA LA 3971-(Assemble)二分答案
- 组装电脑 LA 3971 二分答案
- UVA-LA 3971 组装电脑 二分枚举
- LA 3635 - Pie 【二分】
- LA 3635 Pie (二分)
- LA 4725 Airport 二分 -
- LA-3211-TwoSAT,二分
- LA 4254 二分
- LA 3971 Assemble(组装电脑 最小值最大 二分答案)
- 二分+判断,最小值最大(组装电脑,LA 3971)
- LA 4253 Archery (二分)
- LA 3177 Beijing Guards 二分 -
- LA 4254 Processor 贪心+二分 *
- 二分(派,LA 3635)
- LA 4725 Airport (二分答案)
- La 3971
- WARN No appenders could be found for logger...
- 错误“Unexpected namespace prefix "xmlns" found for tag LinearLayout”的解决方法
- Jtester+unitils+testng:DAO单元测试文件模板自动生成
- CCParticleSystem
- Interpreter(解释器)
- LA 3971 二分
- three.js学习 函数使用方法散记4
- 23种设计模式与原则
- 关于谷歌学术搜索.enw格式批量导入endnote的解决方法
- CCParticleExamples
- Oracle基础知识(十八) - 数值函数
- 贝叶斯网络的训练和推算
- UVa 537 - Artificial Intelligence?
- 欧拉项目004:寻找最大的回文数