zoukankan      html  css  js  c++  java
  • PocketMoney

    PocketMoney
    ( Money.pas/cpp/c)
    Description
    学校为了表彰tsoi的优异成绩, m个领导每人都决定给tsoi的一些人发一些小红包。
    于是n个Tsoier排成一排,等待着收钱。不过由于各种原因,每个人最多只可以收一个红
    包,所以原因你懂的,每个人都会选择最大的那个红包收下- -。
    Input
    第一行两个整数n,m
    接下来m行,每行三个整数l r c。即这个领导计划给第l至r个Tsoier价值为c的红包
    Output
    由于数据较大, 为了减少输出所用的不必要的时间, 请采取以下方法输出: 假如a[i]为第i
    个Tsoier最终收到的钱
    ans := (ans * 1200007 + a[i]) mod 999911659;( 1in)
    SampleInput
    3 2
    1 2 1
    2 2 2
    SampleOutput
    146411103
    Hint
    30% n,m<=5000
    50% n,m <= 10000
    80% n,m <= 500000tsoi Day1 2011.10.6
    100% n <= 1000000, m <= 2000000
    本题时限为4s

    我打的暴力,60分

    正解贪心,然后跳就过掉了。

    先按value由大到小排序,贪心,因为只收最大的。
    用一个数组记录当前有值的右端点,这个右端点意味着从当前的i到右端点已经放了红包,所以直接跳过这一段即可,i=a[i].r。

    #include<iostream>
    #include<cstdio>
    #include<queue>
    #include<algorithm>
    #include<cmath>
    #include<ctime>
    #include<cstring>
    #define mod 999911659
    #define base 1200007
    #define inf 2147483647
    #define For(i,a,b) for(register long long i=a;i<=b;i++)
    #define p(a) putchar(a)
    #define g() getchar()
    //by war
    //2017.10.15
    using namespace std;
    long long ans;
    long long n,m;
    struct packet
    {
        long long l,r,v;
        bool operator<(const packet&aa)const
        {
            return v>aa.v;
        }
    }e[2000010];
    
    struct money
    {
        long long r,v;
    }a[1000010];
    
    void in(long long &x)
    {
        long long y=1;
        char c=g();x=0;
        while(c<'0'||c>'9')
        {
        if(c=='-')
        y=-1;
        c=g();
        }
        while(c<='9'&&c>='0')x=x*10+c-'0',c=g();
        x*=y;
    }
    void o(long long x)
    {
        if(x<0)
        {
            p('-');
            x=-x;
        }
        if(x>9)o(x/10);
        p(x%10+'0');
    }
    int main()
    {
        freopen("money.in","r",stdin);
        freopen("money.out","w",stdout);    
        in(n),in(m);
        For(i,1,m)
        in(e[i].l),in(e[i].r),in(e[i].v);
        sort(e+1,e+m+1);
        For(j,1,m)
        {
        for(long long i=e[j].l;i<=e[j].r;i++)
        {
            if(a[i].v!=0)
            {
                i=a[i].r;
            }
            else
            {
            a[i].v=e[j].v;
            a[i].r=e[j].r;
            }
        }
        }
        For(i,1,n)
        ans=(ans*base+a[i].v)%mod;
        o(ans);
         return 0;
    }
  • 相关阅读:
    Android之MessageQueue、Looper、Handler与消息循环
    Eclipse之相关快捷键
    Android之背景颜色小知识(笔记)
    Android之开发常用颜色
    Android之Handler与AsyncTask的区别
    Android之dip、dp、px、sp和屏幕密度
    the setting of serial port in the SecureCRT
    Raspberry Pi 3 Basic Command and Information
    Raspberry Pi 3 --- identify the version of linux kernal file
    Linux C/C++ ------ “” and <> in the use of head include file(Pending Verification)
  • 原文地址:https://www.cnblogs.com/war1111/p/7674375.html
Copyright © 2011-2022 走看看