标签:des style blog http color os 使用 io strong
Time Limit: 1000MS | Memory Limit: 65536K | |
Total Submissions: 10537 | Accepted: 5264 |
Description
Input
Output
Sample Input
59 237 375 743 200000 849694 2500000 8000000
Sample Output
116 28 300612 Deficit
题目意思:MS公司在1999年每个月有盈余有亏损,现在只知道盈余一定为s,亏损一定为d,并且该公司每连续五个月的总利润都是亏损(0-4,1-5,...7-11)(编号0-11),问如何取值(s,-d)在该条件下使得总利润最大,并且询问总利润是否可能为正数(盈利)
思路:贪心,一开始是统计需要次数最多的那个点,但是那样容易造成断层,(比如第二组数据375 473,5 6 7 8都是被需要次数相同的,这个算法就不知道该先选择哪个,可能会先选择5,6,而4是一定要选的,选了4就不用选6了)
改变贪心思路,初始化全部选s,从头往尾扫,每个sum都必须变成-的为止,那么选择最右边的大于0,因为左边的要不就已经变成-的,或者使用次数没有右边多,直到sum变成负数为止
#include <cstdio> #include <cstring> #include <algorithm> using namespace std; int s,d; int a[12]; long long sum[8]; int main() { while(scanf("%d%d",&s,&d)==2){ for(int i=0;i<11;i++)a[i]=s; for(int i=0;i<8;i++)sum[i]=5*s; for(int i=0;i<8;i++){ int t=4; while(sum[i]>=0){ a[i+t]=-d; for(int j=max(i+t-4,0);j<8&&j<=i+t;j++){ sum[j]-=d+s; } t--; } } long long ans=sum[0]+sum[7]+a[5]+a[6]; if(ans>=0)printf("%I64d\n",ans); else printf("Deficit\n"); } return 0; }
标签:des style blog http color os 使用 io strong
原文地址:http://www.cnblogs.com/xuesu/p/3941288.html