Present Problem

     A group of persons (indexed from 0 to n − 1) play a game to determine which of the n presents (also indexed from 0 to n − 1) each of them will get. They play the game on a system of n vertical “lines”, numbered from 0 to n − 1, from left to right. Person i initially is at the top of line i, and present i is at the bottom of line i. All lines have length l. There are also horizontal “links” that connect two adjacent lines i and i + 1 at the same length k, where k is an integer distance from the top end of the line, and 0 < k < l. We use link (i, k) to denote this link. In addition, two links adjacent to a line cannot be at the same length of the line. That is, we cannot have both links (i, k) and (i + 1, k). Person i determines which present he will receive as follows. He will start from the top of line i and go downward. Whenever he encounters an intersection of a line and a link, he has to make a turn, and he can go either left or right along a link, or downward along a line. Finally he will reach the bottom of a line j, and he will receive present j.

 We use Figure 1 to illiterate the rules. Person 1 starts from the top of line 1 and goes downward. He first reaches the link at (1, 1) and makes a turn to line 2, and keeps going downward. Then he reaches the link at (2, 3) and makes another turn to line 3. He keeps on going, as indicated by the path in Figure 1, and finally reaches present 4.

  Your task is to determine for all persons, what presents do they receive, and list the present indices from person 0 to person n − 1. In the previous example you should output 3, 4, 1, 0, 5, 2, because person 0 will get present 3, person 1 will get present 4, and so on

Technical Specification

1. 1 ≤ n ≤ 10, 000, where n is the number of lines.

2. 1 ≤ m ≤ 100, 000, where m is the number of links.

3. 1 ≤ l ≤ 10, 000, where l is the length of the lines

 

Input

The first line of the input has the number of test cases c. For each test case, the first line has n, m, and l, indicating the number of lines, the number of links, and the length of the lines respectively. Each of the next m lines contains two integers i and k, to indicate a link at (i, k).

Output

For each test case, your should output n lines, where the i-line is the present id person i will receive.

Sample Input
1
6 10 8
0 2
2 6
0 7
1 1
4 2
4 5
1 4
2 3
3 4
4 7
Sample Output
3
4
1
0
5
2

 

题意:看每个人的礼物是什么,要求每个人都遇到分叉时就按这个走,题目有个坑 ,样例中的6 10 8 中的8,而题目中只给了1到7,所以8应该是礼物所放的行数。

#include<stdio.h>
#include<string.h>
#include <iostream>
#include <bits/stdc++.h>
#define MAX 0x3f3f3f3f
using namespace std;
typedef long long ll;
ll mapp[10010][10010];
int main()
{
    ll n,m,l,i,j,k,T,a,b;
    cin>>T;
    while(T--)
    {
        memset(mapp,0,sizeof(mapp));
        cin>>n>>m>>l;
        for(i=1;i<=m;i++)
        {
            cin>>a>>b;
            mapp[a][b]=1;//往右走
            mapp[a+1][b]=2;//往左走
        }
        for(i=0;i<n;i++)
        {
            ll x=i;
            for(j=1;j<=l;j++)
            {
                if(mapp[x][j]==1)
                    x++;
                else
                if(mapp[x][j]==2)
                    x--;
            }
            cout<<x<<endl;
        }
    }
    return 0;
}

 

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值