码迷,mamicode.com
首页 > 其他好文 > 详细

PocketMoney

时间:2017-10-15 22:28:44      阅读:150      评论:0      收藏:0      [点我收藏+]

标签:etc   day   putchar   数据   价值   mod   col   input   struct   

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;
}

 

PocketMoney

标签:etc   day   putchar   数据   价值   mod   col   input   struct   

原文地址:http://www.cnblogs.com/war1111/p/7674375.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!