Hdu 4525 威威猫系列故事——吃鸡腿
题目连接:http://acm.hdu.edu.cn/showproblem.php?pid=4525
腾讯马拉松初赛第六场第一题。
水题。但是要注意输入可能为double型。负负得正。注意这两点就行了。
#include <iostream>#include <stdio.h>#include <stdlib.h>#include <string.h>#include <math.h>#include <algorithm>#include <stack>#include <queue>using namespace std;int main(){#ifndef ONLINE_JUDGE freopen("in.txt","r",stdin);#endif int t; int cas = 0; int n; double k1,k2; double k; double sum = 0; scanf(" %d",&t); while(t--) { sum = 0; cas++; scanf(" %d %lf %lf %lf",&n,&k1,&k2,&k); for(int i=0;i<n;i++) { double a; scanf(" %lf",&a); sum += a; } double kk = k1 + k2; if(sum>k) { printf("Case #%d: 0\n",cas); continue; } int day = 0; while(true) { day++; if(kk<=1 && kk>=-1) { printf("Case #%d: inf\n",cas); break; } sum *= kk; if(sum>k) { printf("Case #%d: %d\n",cas,day); break; } } } return 0;}