CodeForces474B - Worms - 暴力标记

时间:2020-06-28 23:10:05   收藏:0   阅读:75

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

思路:
给当前连续的堆进行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

评论(0
© 2014 bubuko.com 版权所有 - 联系我们:wmxa8@hotmail.com
打开技术之扣,分享程序人生!