Online Judge | Problem Set | Authors | Online Contests | User | ||||||
---|---|---|---|---|---|---|---|---|---|---|
Web Board Home Page F.A.Qs Statistical Charts | Current Contest Past Contests Scheduled Contests Award Contest |
此题极坑,说说一个关键点,附代码主人公可能有多次买入和卖出,一定要注意! #include <stdio.h> int main() { int m, n, k, i, j,l,r; double pm[10010], pn[10010]; double eps=1e-9; double sum[10010],a[10010]; scanf("%d %d %d", &m, &n, &k); sum[0]=0; for (i = 1; i <= k; i++){ scanf("%lf", &a[i]); sum[i]=sum[i-1]+a[i]; } for (i = m; i <= k; i++) pm[i] = (double)(sum[i]-sum[i-m])/m; for (i = n; i <= k; i++) pn[i] = (double)(sum[i]-sum[i-n])/ n; if(pm[n] - pn[n] > eps) printf("BUY ON DAY %d\n", n); else if(pn[n] - pm[n] > eps) printf("SELL ON DAY %d\n", n); for(i = n+1; i <= k; i++) if(pm[i] - pn[i] > eps && pn[i-1] - pm[i-1] > eps) printf("BUY ON DAY %d\n", i); else if(pn[i] - pm[i] > eps && pm[i-1] - pn[i-1] > eps) printf("SELL ON DAY %d\n", i); return 0; } Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator