HNU Profits
来源:互联网 发布:域名注册的要求 编辑:程序博客网 时间:2024/05/17 03:08
In a business of diamond mining from a river, the government allows you to put the machine in theriver only once, and you must remove the machine passing certain deadline. However, you can removeit at any time after you put the machine in the river. The machine in your company requires diamond inorder to operate (it is used as the drilling head). Your company has a smart detector that can predict thenumber of diamond that you will gain or loss each day, from the first day to the last day that thegovernment grants the request. You are tasked with creating a program. This program finds the periodthat your company can gain the most diamond.
Input
The first line contains one number, N ? the total number of test cases, 1 <= N <= 2000. Each of thefollowing N lines contains a single test case. Each test case has M + 1 numbers. The first number is M? the total number of days granted by the government, 1<= M <= 500. The following M numbers arethe predicted of gain and loss of diamond on each day. The number of diamond loss or gains is within[-100,100]. All input numbers are integer.q
Output
The output contains N lines (one line per one test case). For each test case, the program must print out 3numbers, the beginning day, the ending day, and the maximum total profits. The first day in the input isconsidered “1”. The last day in the input is considered “M”. If there is no positive profit, the outputmust be “0 0 0”. In case of a tie of profits of two time periods, choose the time period with is shorterfirst. If the time periods and profits are the same for both periods, pick the time period that begins first.
Sample Input
616 4 3 -10 3 -1 2 0 -3 5 7 -4 -8 -10 4 7 -306 -1 0 -3 -1 0 -110 -1 -4 -5 -9 -14 5 6 7 -10 103 -2 -3 -417 1 2 3 4 5 6 7 8 9 -10 -11 10 9 8 -7 -6 137 1 2 3 -10 3 2 1
Sample Output4 10 130 0 06 8 180 0 01 14 511 3 6
题意说的乱七八糟的 其实就是求最大连续子序列和 然后还要输出子序列的起点和终点
很简单的dp 主要是记录下标 用s[i]数组存储以i位置作为子序列重点时 子序列起点的下标
这个题有输出的要求 要是利益相同输出时间短的 要是利益跟时间都相同就输出最先出现的
#include<iostream>#include <cstdio>using namespace std;int s[10001],a[10001],f[10001];int main(){//freopen("test.txt","r",stdin); int n,i,mx,st,ed; bool flag; int tc; scanf("%d",&tc); while(tc--) { int n; scanf("%d",&n); for(i=1; i<=n; i++) scanf("%d",&a[i]); f[1]=a[1]; s[1]=1; for(i=2; i<=n; i++) { if(f[i-1]+a[i]>a[i]) { f[i]=f[i-1]+a[i]; s[i]=s[i-1]; } else { f[i]=a[i]; s[i]=i; } } /* for(i=1;i<=n;i++) cout<<f[i]<<" "; cout<<endl;*/ mx=0; st=1; ed=1; for(i=1; i<=n; i++) { if(f[i]>mx) { mx=f[i]; st=s[i]; ed=i; } if(f[i]==mx) { int l=s[i]; int r=i; if((r-l)<(ed-st)) { st=l; ed=r; } } } if(mx>0) cout<<st<<" "<<ed<<" "<<mx<<endl; else cout<<0<<" "<<0<<" "<<0<<endl; }return 0;}
- HNU Profits
- G - Profits
- luogu3009 [USACO11JAN]利润Profits
- HNU 11877
- hnu 病毒
- hnu 12948
- HNU 21
- GO MOBILE Increase Web Profits NOW!
- USACO 2011 Jan Profits 公司利润
- HLJU 1036: Teamwork Brings Profits! (dfs)
- USACO 2011 Jan Silver 1.Profits
- acm hnu 10136 Palindromes
- hnu 12029 LCA问题
- hnu 12439 #贪心
- [讨论]hnu 12450 Painting
- hnu-City Merger
- hnu-Kitchen Robot
- HNU 12813 Restore Calculation
- 【一些题】剑指offer:连续子数组最大和
- 彻头彻尾理解KMP
- C语言scanf()函数返回值的问题(实验一)
- Unity shader 官网文档全方位学习(一)————Surface Shaders基础及Examples详尽解析
- HDU 2152 Fruit (母函数)
- HNU Profits
- C++对文件的操作
- Tree Cutting - POJ 2378 树形dp
- 【软件工程】软工概述
- hdu5029 树链剖分
- Android内存泄漏分析及调试
- 对java继承,多态,抽象类,接口的理解
- 【BZOJ2120】数颜色 循环
- 会场安排问题 贪心算法