评论

收藏

[R语言] HDU 1692 Destroy the Well of Life 水题

编程语言 编程语言 发布于:2021-07-20 16:53 | 阅读数:206 | 评论:0

Destroy the Well of LifeTime Limit: 1 Sec  Memory Limit: 256 MB


题目连接
http://acm.hdu.edu.cn/showproblem.php?pid=1692

Description
In the game of DotA (Defense of the Ancient), there are two opposite legions called The Sentinel and The Scourage.
Now The Scourage has made a big success and The Sentinel is at stake!
So The Sentinel must destroy the Well of Life of The Scourage.
The chief of The Sentinel, Prophet, asks EarthShaker to do this arduous task.

There are N Wells of Life of The Scourage (The Wells of Life are numbered from 1 to N), and EarthShaker’s task is to destroy the Nth Well of Life.
The following information is known about each Well of Life:
Wi – the weight of water on i-th Well of Life before it is destroyed.
Li – if the weight of water on i-th Well of Life is more than Li, the i-th Well of Life will be destroyed and the water of it will pours to the (i + 1)-th Well of Life.
Pi – EarthShaker has a skill called Echo-Slam, the i-th Well of Life will be immediately destroyed when he uses Echo-Slam to it and the water of it will pours to the (i + 1)-th Well of Life. For the i-th Well of Life, the energy that EarthShaker need to use Echo-Slam to destroy it is Pi.

Can you tell EarthShaker the minimum amount of energy needed to destroy the Nth Well of Life?

Input

The input consists of several test cases. There is a single number on the first line, the number of cases. There are no more than 10 cases.
Each case contains a natural number N on the first line, 1<=N<=100,000.
Following N lines contains three numbers Wi, Li, Pi (Wi<=Li, 0<=Wi, Li, Pi <=20,000), representing the information of the i-th Well of Life.

Output

For each case, print a number in a line representing the least amount of energy EarthShaker needed to use, so as to destroy the Nth Well of Life. Use the format in the sample.

Sample Input

1
3
1000 1000 1 
0 1000 2 
2 10 100
Sample Output

Case 1: Need to use 3 mana points.

HINT
题意
告诉你有N口井,每摧毁一口井就会给下一口井xL,当这口井超过yL的时候,就会爆炸,然后给下一口井xL,摧毁这口井的代价是Z,然后问你,我想要摧毁最后一口井,所需要的最小代价是多少?
题解:
数据范围太小了,什么都不需要,直接乱搞就好了
代码:
//qscqesze
#include <cstdio>
#include <cmath>
#include <cstring>
#include <ctime>
#include <iostream>
#include <algorithm>
#include <set>
#include <vector>
#include <sstream>
#include <queue>
#include <typeinfo>
#include <fstream>
#include <map>
typedef long long ll;
using namespace std;
//freopen("D.in","r",stdin);
//freopen("D.out","w",stdout);
#define sspeed ios_base::sync_with_stdio(0);cin.tie(0)
#define maxn 100005
#define mod 10007
#define eps 1e-9
//const int inf=0x7fffffff;   //无限大
const int inf=0x3f3f3f3f;
/*

*/
//**************************************************************************************
inline ll read()
{
  int x=0,f=1;char ch=getchar();
  while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}
  while(ch>='0'&&ch<='9'){x=x*10+ch-'0';ch=getchar();}
  return x*f;
}
struct node
{
  int x,y,z;
};
node a[maxn];
int main()
{
  int t=read();
  for(int cas=1;cas<=t;cas++)
  {
    memset(a,0,sizeof(a));
    int n=read();
    for(int i=0;i<n;i++)
      a[i].x=read(),a[i].y=read(),a[i].z=read();
    int ans=a[n-1].z;
    for(int i=0;i<n;i++)
    {
      int sum=0,ma=0;
      for(int j=i;j<n;j++)
      {
        ma+=a[j].x;
        if(ma<=a[j].y)
          sum+=a[j].z;
        //cout<<ma<<" "<<a[j].y<<" "<<sum<<endl;
        if(sum>ans)
          break;
      }
      ans=min(ans,sum);
    }
    printf("Case %d: Need to use %d mana points.\n",cas,ans);
  }
}

关注下面的标签,发现更多相似文章