hdu 1692 Destroy the Well of Life
题目分析: 重点:要摧毁第N个井,而不是n个井,在这我纠结了好长时间 思路:可以从1->n也可以N->1选出最小的就ok了 技巧:不能暴力求最小值,会超时;巧用break;
#include<stdio.h> int l[100001]; int r[100001]; int sum[100001]; int main() { //freopen("e:1.txt","r",stdin); int n,T,t=0; scanf("%d",&T); while(T--) { int i,max; scanf("%d",&n); for(i = 0;i < n;i++) scanf("%d%d%d",&l[i],&r[i],&sum[i]); int min=sum[n-1],msum; for(i=0;i<n-1;i++) { max=0; msum=0; for(int j = i;j < n;j++) { max+=l[j]; if(max <= r[j]) msum+=sum[j]; if(msum>min) break; } if(msum < min) min=msum; } printf("Case %d: Need to use %d mana points.\n",++t,min); } return 0; }
Just a little, maybe change the world