CodeForces474B

题意:判断第二组数据在第一组数据的哪一堆中。

思路:
给当前连续的堆进行book标记,同一堆标记成一样的就可以了。
最后输出询问的数据所在book的位置。

AC代码:

#include <iostream>
#include <string.h>
#include <algorithm>
#include <cmath>
#include <map>

using namespace std;
typedef long long ll;

int book[1000200];

int main()
{
    int n,m;
    cin>>n;
    int k=1,kk=1,t=1;
    for(int i=0;i<n;i++)
    {
        int x;
        cin>>x;
        for(int j=1;j<=x;j++)
            book[t++]=k;
        k++;
    }
    cin>>m;
    for(int i=0;i<m;i++)
    {
        int x;
        cin>>x;
        cout<<book[x]<<endl;
    }
    return 0;
}
原文地址:https://www.cnblogs.com/OFSHK/p/13205233.html