zoukankan      html  css  js  c++  java
  • 10026

     Shoemaker's Problem 

    Shoemaker has N jobs (orders from customers) which he must make. Shoemaker can work on only one job in each day. For each ith job, it is known the integer Ti (1<=Ti<=1000), the time in days it takes the shoemaker to finish the job. For each day of delay before starting to work for the ith job, shoemaker must pay a fine of Si (1<=Si<=10000) cents. Your task is to help the shoemaker, writing a programm to find the sequence of jobs with minimal total fine.

    The Input

    The input begins with a single positive integer on a line by itself indicating the number of the cases following, each of them as described below. This line is followed by a blank line, and there is also a blank line between two consecutive inputs.

    First line of input contains an integer N (1<=N<=1000). The next N lines each contain two numbers: the time and fine of each task in order.

    The Output

    For each test case, the output must follow the description below. The outputs of two consecutive cases will be separated by a blank line.

    You programm should print the sequence of jobs with minimal fine. Each job should be represented by its number in input. All integers should be placed on only one output line and separated by one space. If multiple solutions are possible, print the first lexicographically.

    Sample Input

    1
    
    4
    3 4
    1 1000
    2 2
    5 5
    

    Sample Output

    2 1 3 4
    

    Alex Gevak
    September 16, 2000(Revised 4-10-00, Antonio Sanchez)
    #include<cstdio>
    #include<cstring>
    #include<cstdlib>
    #include<cmath>
    #include<algorithm>
    #include<string>
    #include<map>
    #include<stack>
    #include<set>
    #include<iostream>
    #include<vector>
    #include<queue>
    //ios_base::sync_with_stdio(false);
    //#pragma comment(linker, "/STACK:1024000000,1024000000")
    
    using namespace std;
    #define sz(v) ((int)(v).size())
    #define rep(i, a, b) for (int i = (a); i < (b); ++i)
    #define repf(i, a, b) for (int i = (a); i <= (b); ++i)
    #define repd(i, a, b) for (int i = (a); i >= (b); --i)
    #define clr(x) memset(x,0,sizeof(x))
    #define clrs( x , y ) memset(x,y,sizeof(x))
    #define out(x) printf(#x" %d
    ", x)
    #define sqr(x) ((x) * (x))
    typedef long long LL;
    
    const int INF = 1000000000;
    const double eps = 1e-8;
    const int maxn = 3000;
    
    int sgn(const double &x) {  return (x > eps) - (x < -eps); }
    
    struct Job
    {
        int t;
        int f;
        int id;
    }J[maxn];
    
    bool cmp(Job j1,Job j2)
    {
        return j1.t*j2.f < j1.f*j2.t;
    }
    int main() 
    {
        //freopen("in.txt","r",stdin);
    
        int T;
        cin>>T;
        int first = 0;
        while(T--)
        {
            if(first)
                cout<<endl;
            first = 1;
            int n;
            cin>>n;
            repf(i,1,n)
            {
                scanf("%d%d",&J[i].t,&J[i].f);
                J[i].id = i;
            }
            
            sort(J+1,J+n+1,cmp);
            cout<<J[1].id;
            repf(i,2,n)
                cout<<" "<<J[i].id;
            cout<<endl;
            
        }
        return 0;
    }

  • 相关阅读:
    设计和实现OLAP解决方案
    数据库的数据挖掘概述
    SharePoint 2007中的搜索服务 Virus
    分离SharePoint的应用服务器的过程中遇到的问题 Virus
    自定义对象的比较系列二之实现IComparable Virus
    软件行业和传统行业的比较 Virus
    Sharepoint中用treeview来显示组织机构的人员状态的webpart Virus
    自定义对象的比较系列一之实现IComparable Virus
    无法保存webpart的属性设置,发生意外,异常来自 HRESULT:0x80020009(DISP_E_EXCEPTION) Virus
    SPD开发工作流需要注意的地方3[SPD工作流访问隐藏栏] Virus
  • 原文地址:https://www.cnblogs.com/DreamHighWithMe/p/3381606.html
Copyright © 2011-2022 走看看