接下来的n行, 每行两个数, 分别代表该首歌要循环放几次, 一次放多久
然后最后一行输入m个时间点, 求在这m个时间点里, 每个时间点是在放哪首歌?
做法: 直接for循环了, 也有二分法做法
AC代码:
#include<stdio.h>
int n, m;
int songList[311111];
int time[311111];
int main() {
while(scanf("%d %d", &n, &m) != EOF) {
songList[0] = 0;
for(int i = 1; i <= n; i++) {
int v, c;
scanf("%d %d", &v, &c);
songList[i] = v * c + songList[i-1];
}
for(int i = 0; i < m; i++)
scanf("%d", &time[i]);
int begin = 1;
for(int i = 0; i < m; i++) {
for(int j = begin; j <= n; j++) {
if(time[i] > songList[j-1] && time[i] <= songList[j]) {
printf("%d\n", j);
begin = j;
break;
}
}
}
}
return 0;
}