zoukankan      html  css  js  c++  java
  • BZOJ 1151 傲娇的人 排序

    傲娇的人

    Time Limit: 1 Sec  

    Memory Limit: 256 MB

    题目连接

    http://acm.uestc.edu.cn/#/problem/show/1151

    Description

    有 N 个傲娇的人,你要指派他们去完成工作。只有当现在被指派的人完成了工作,你才能指派下一个。每个人完成工作需要花费 Ti 分钟,但!他们都好傲娇,他们都希望你马上就指派他,如果你拖延了 t 分钟才指派他,那么就需要付给他 tCi 元钱作为补偿。问,最少需要花费多少元钱才能去指派所有傲娇的人?

    Input

    第一行输入一个整数N (1N105)

    第二行输入四个种子数abcd (1abcd10007)。你需要通过这4个种子数来得到 Ti 和 Ci,方法如下:

    const int mod=10007;
    typedef long long ll;
    void getdata(int a,int b,int c,int d,int N,int *T,int *C){
        T[0]=C[0]=0;
        for(int i=1;i<=N;i++){
            T[i]=(T[i-1]*a+b)%mod+1;
            C[i]=(C[i-1]*c+d)%mod+1;
        }
    }

    Output

    第一行输出一个整数,表示最少需要花费多少钱去指派这些傲娇的人。

    第二行输出 N 个整数,表示每次指派哪个人去,即按指派顺序输出被指派人的编号。比如,有5个人,按顺序指派他们,则输出"1 2 3 4 5"。如果有多解,输出字典序最小解。

    Sample Input

    5
    1 1 1 1

    Sample Output

    340 
    1 2 3 4 5

    HINT

    题意

    题解:

    排个序就好了

    每个值对于后面的贡献度就是T[i]*其他的C[i]

    然后根据这个排序就吼了

    代码:

    //qscqesze
    #include <cstdio>
    #include <cmath>
    #include <cstring>
    #include <ctime>
    #include <iostream>
    #include <algorithm>
    #include <set>
    #include <bitset>
    #include <vector>
    #include <sstream>
    #include <queue>
    #include <typeinfo>
    #include <fstream>
    #include <map>
    #include <stack>
    typedef long long ll;
    using namespace std;
    //freopen("D.in","r",stdin);
    //freopen("D.out","w",stdout);
    #define sspeed ios_base::sync_with_stdio(0);cin.tie(0)
    #define maxn 200500
    #define mod 10007
    #define eps 1e-9
    #define pi 3.1415926
    int Num;
    //const int inf=0x7fffffff;
    const ll inf=999999999;
    inline ll read()
    {
        ll x=0,f=1;char ch=getchar();
        while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}
        while(ch>='0'&&ch<='9'){x=x*10+ch-'0';ch=getchar();}
        return x*f;
    }
    //*************************************************************************************
    
    ll T[maxn];
    ll C[maxn];
    struct node
    {
        ll x,y,z;
        friend bool operator < (const node & a,const node & b)
        {
            if(a.x*b.y<a.y*b.x)return true;
            else if( a.x*b.y==a.y*b.x && a.z<b.z)return true;
            return false;
        }
    };
    node ans[maxn];
    int main()
    {
        int n=read();
        int a=read(),b=read(),c=read(),d=read();
        for(int i=1;i<=n;i++)
        {
            ans[i].z=i;
            ans[i].x=(ans[i-1].x*a+b)%mod+1;
            ans[i].y=(ans[i-1].y*c+d)%mod+1;
        }
        sort(ans+1,ans+1+n);
        ll now = 0,Ans = 0;
        for(int i=1;i<=n;i++)
            Ans += now * ans[i].y,now += ans[i].x;
        printf("%lld
    ",Ans);
        for(int i=1;i<=n;i++)
        {
            if(i==1)
                printf("%d",ans[i].z);
            else
                printf(" %d",ans[i].z);
        }
        printf("
    ");
    }
  • 相关阅读:
    jquery radio set checked.
    Java Reflect
    Java Collection
    hashcode and equals
    Statement VS PrepareStatement
    第十六章 调试及安全性(In .net4.5) 之 调试程序
    第十五章 调试及安全性(In .net4.5) 之 管理程序集
    第十四章 调试及安全性(In .net4.5) 之 对称及非对称加密
    第十三章 调试及安全性(In .net4.5) 之 验证程序输入
    第十二章 管理类型(In .net4.5) 之 操作字符串
  • 原文地址:https://www.cnblogs.com/qscqesze/p/4796325.html
Copyright © 2011-2022 走看看