標籤:
題意:王子每月買m個燈泡給n個房間換燈泡,如果當前有的燈泡數夠列表的第一個房間換的就全換,直到燈泡不夠為止,給出q個查詢,查詢x月已經換好幾個房子,手裡還剩多少燈泡。
解法:水題……小類比。
代碼:
#include<stdio.h>#include<iostream>#include<algorithm>#include<string>#include<string.h>#include<math.h>#include<limits.h>#include<time.h>#include<stdlib.h>#include<map>#include<queue>#include<set>#include<stack>#include<vector>#define LL long longusing namespace std;int a[1005], ans[100005][2];int main(){ int n, m; while(~scanf("%d%d", &n, &m)) { int cnt = 0; for(int i = 0; i < n; i++) { scanf("%d", &a[i]); } ans[0][0] = 0, ans[0][1] = 0; int j = 0; for(int i = 1; i <= 100000; i++) { cnt++; ans[i][0] = ans[i - 1][0]; ans[i][1] = ans[i - 1][1] + m; while(j < n && a[j] <= ans[i][1]) { ans[i][0]++; ans[i][1] -= a[j]; j++; } if(j == n) break; } int q; scanf("%d", &q); while(q--) { int x; scanf("%d", &x); if(x > cnt) x = cnt; printf("%d %d\n", ans[x][0], ans[x][1]); } } return 0;}
CF GYM 100703B Energy Saving