HDOJ 4393 Throw nails —— 思维题

Throw nails

Time Limit: 5000/2000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 1101    Accepted Submission(s): 343


Problem Description
The annual school bicycle contest started. ZL is a student in this school. He is so boring because he can't ride a bike!! So he decided to interfere with the contest. He has got the players' information by previous contest video. A player can run F meters the first second, and then can run S meters every second.
Each player has a single straight runway. And ZL will throw a nail every second end to the farthest player's runway. After the "BOOM", this player will be eliminated. If more then one players are NO.1, he always choose the player who has the smallest ID.
 

Input
In the first line there is an integer T (T <= 20), indicates the number of test cases.
In each case, the first line contains one integer n (1 <= n <= 50000), which is the number of the players. 
Then n lines follow, each contains two integers Fi(0 <= Fi <= 500), Si (0 < Si <= 100) of the ith player. Fi is the way can be run in first second and Si is the speed after one second .i is the player's ID start from 1.
Hint

Huge input, scanf is recommended.
Huge output, printf is recommended.
 

Output
For each case, the output in the first line is "Case #c:".
c is the case number start from 1.
The second line output n number, separated by a space. The ith number is the player's ID who will be eliminated in ith second end.
 

Sample Input
  
  
2 3 100 1 100 2 3 100 5 1 1 2 2 3 3 4 1 3 4
 

Sample Output
  
  
Case #1: 1 3 2 Case #2: 4 5 3 2 1
Hint
Hint The first case: 1st Second end Player1 100m (BOOM!!) Player2 100m Player3 3m 2nd Second end Player2 102m Player3 103m (BOOM!!) 3rd Second end Player2 104m (BOOM!!)
 

Source
 

Recommend
zhuyuanchen520
 
题意是给你n个人的初始位置和速度,每秒都输出当前最远的人的序号。
一开始想的是优先队列,TLE。。。
后来得知,因为初始位置小于500,所以500s后所有人的顺序只与速度有关,直接输出即可。
#include <cstdio>
#include <cmath>
#include <algorithm>
#include <iostream>
#include <cstring>
#include <map>
#include <string>
#include <stack>
#include <cctype>
#include <vector>
#include <queue>
#include <set>
#include <utility>

using namespace std;
//#define Online_Judge
#define outstars cout << "***********************" << endl;
#define clr(a,b) memset(a,b,sizeof(a))
#define lson l , mid  , rt << 1
#define rson mid + 1 , r , rt << 1 | 1
#define mid ((l + r) >> 1)
#define mk make_pair
#define FOR(i , x , n) for(int i = (x) ; i < (n) ; i++)
#define FORR(i , x , n) for(int i = (x) ; i <= (n) ; i++)
#define REP(i , x , n) for(int i = (x) ; i > (n) ; i--)
#define REPP(i ,x , n) for(int i = (x) ; i >= (n) ; i--)
const int MAXN = 50000 + 500;
const long long LLMAX = 0x7fffffffffffffffLL;
const long long LLMIN = 0x8000000000000000LL;
const int INF = 0x7fffffff;
const int IMIN = 0x80000000;
const double e = 2.718281828;
#define eps 1e-8
#define DEBUG 1
#define mod 1000000007
typedef long long LL;
const double PI = acos(-1.0);
typedef double D;
typedef pair<int , int> pi;
///#pragma comment(linker, "/STACK:102400000,102400000")__int64 a[10050];

int n;
struct Node
{
    int s;
    int num;
    int val;
    int vis;
}a[MAXN];
bool cmp(const Node a , const Node b)
{
    if(a.vis != b.vis)return a.vis < b.vis;
    if(a.val != b.val)return a.val > b.val;
    return a.num < b.num;
}
int main()
{
    int t;
    scanf("%d" , &t);
    FORR(kase , 1 ,t)
    {
        scanf("%d" , &n);
        printf("Case #%d:\n" , kase);
        a[0].val = INF;
        a[0].num = 0;
        a[0].s = 0;
        a[0].vis = -1;
        int MAXNUM = -1 , inum = 0;
        FORR(i , 1 , n)
        {
            scanf("%d%d" , &a[i].val , &a[i].s);
            a[i].num = i;
            a[i].vis = 1;

        }
        FORR(i , 1,  n)
        {
            if(MAXNUM < a[i].val)
            {
                MAXNUM = a[i].val;
                inum = i;
            }
        }
        a[inum].vis = -1;
        printf("%d" , a[inum].num);
        FORR(j , 2 , min(n , 502))
        {
            MAXNUM = -1;
            FORR(i , 1 , n)
            {

                if(a[i].vis == -1)continue;
                a[i].val += a[i].s;
                if(MAXNUM < a[i].val)
                {
                    MAXNUM = a[i].val;
                    inum = i;
                }
            }

            a[inum].vis = -1;
            printf(" %d" , inum);
        }
        sort(a, a + n + 1, cmp);
        FORR(i , 503 , max(n , 502))
        {
            printf(" %d" , a[i].num);
        }
        printf("\n");
    }
    return 0;
}


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值