zoukankan      html  css  js  c++  java
  • ZOJ 3981(Balloon Robot)

    题目链接

    题目意思:n支队伍,一张桌子有m个座位顺时针编号1~m。p个预言。预言a队伍在b时刻ac一道题目。机器人每个时刻都顺时针走一步,有需要气球的就发。每支队伍,ac后多少时刻没收到气球就有多少不开心的值,问机器人起始位置在哪里可以使得总的不高兴值最小。输出最小的不高兴值。

    思路:把每次预言转一下,a,b。那就让a队伍位置往前推b的位置值加一。那么不高兴值就是机器人花费时间乘以值求和。然后换起始点可以O(1)转。

    #include <stdio.h>
    #include <iostream>
    #include <algorithm>
    #include <string.h>
    #include <string>
    #include <vector>
    #include <map>
    
    using namespace std;
    typedef long long int LL;
    
    
    const int maxn=1e6+10;
    int n,m,p;
    map<int,int>val;
    int pos[maxn];
    
    int main()
    {
        int T;
        scanf("%d",&T);
        while(T--)
        {
            scanf("%d%d%d",&n,&m,&p);
            val.clear();
            for(int i=1;i<=n;i++) scanf("%d",&pos[i]);
            for(int i=1;i<=p;i++)
            {
                int x,y;
                scanf("%d%d",&x,&y);
                LL p=((pos[x]%m)*1ll-y+(1000000000ll/m+1)*m)%m;
                val[(int)(p)]++;
            }
            LL sum=0,base=0,ans;
            int st=val.begin()->first;;
            for(map<int,int>::iterator i=val.begin();i!=val.end();i++)
            {
                sum+= i->second;
                base+=(1ll*i->second*(i->first - st));
            }
            ans=base;
            int prekey;
            map<int,int>::iterator it=val.begin();
            prekey=it->first;
            int preval=it->second;
            it++;
            for(;it!=val.end();it++)
            {
                int dt=it->first-prekey;
                base=base-((sum-preval)*dt)+(m-dt)*preval;
                ans=min(base,ans);
                prekey=it->first;
                preval=it->second;
            }
            cout<<ans<<endl;
        }
        return 0;
    }
    
    
    
  • 相关阅读:
    论文笔记:语音情感识别(五)语音特征集之eGeMAPS,ComParE,09IS,BoAW
    《Grammar and Punctuation》课堂笔记
    《Sequence Models》课堂笔记
    【翻译】学术写作中的数字
    生成器
    使用序列生成字典
    字典 (dictionary) 的默认值
    如何阅读文献 (How to Read a Paper)
    Python 列表的连接和联合
    《Convolutional Neural Networks》课堂笔记
  • 原文地址:https://www.cnblogs.com/coded-ream/p/7762718.html
Copyright © 2011-2022 走看看