标签:void ++ style include stream 端点 for find cst
题意:花有一个最适的温度范围 l 和 r ,如果等于这个范围其价值为a, 高于为b,等于为c,求最大的价值
思路:如果一一枚举肯定超时,所有把每个区间的端点都存在一个结构体里,-1为左, 1为右,再从小到大排序,假设起点从负无穷小开始(sum = 所有的c),一一遍历每个端点,求出最大值。
#include <iostream> #include <queue> #include <cstdio> #include <algorithm> using namespace std; struct A { int dian; int f; int num; }p[50000*2]; int a[50005], b[50005], c[50005]; long long sum = 0; int n; int Min; int j; bool cmp(A a, A b) { if(a.dian != b.dian) return a.dian < b.dian; else return a.f < b.f; } void Input() { sum = 0; cin >> n; int l, r; j = 0; for(int i = 0; i < n; i++) { scanf("%d%d%d%d%d", &l, &r, &a[i], &b[i], &c[i]); p[j].dian = l; p[j].f = -1; p[j].num = i; j++; p[j].dian = r; p[j].num = i; p[j].f = 1; j++; sum += c[i]; } sort(p, p+j, cmp); } void finds() { long long Sum = 0; Sum = max(Sum, sum); for(int i = 0; i < j; i++) { int l = i; while(p[i].dian == p[i+1].dian && p[i].f == p[i+1].f)i++; for(int k = l; k <= i; k++) { if(p[k].f == -1)sum += a[p[k].num] - c[p[k].num]; else sum += b[p[k].num] - a[p[k].num]; } Sum = max(Sum, sum); } cout << Sum << endl; } int main() { int t; cin >> t; while(t--) { Input(); finds(); } return 0; }
HDU 6012 Lotus and Horticulture
标签:void ++ style include stream 端点 for find cst
原文地址:http://www.cnblogs.com/liuqiyu/p/7290759.html