Codeforces Round #279 (Div. 2) B - Queue 水题

#include<iostream>
#include<mem.h>
using namespace std;
int p[1000001],q[1000001];
int main()
{
    int n,x,y;
    memset(q,0,sizeof(q));
    cin>>n;
    while(n)
    {
        cin>>x>>y;
        p[x]=y;
        q[x]++;
        q[y]--;
        n--;//p[x]表示在x之后两位的数是什么
        //q[x]表示x这个数究竟有多少个
    }
    int i=0;
    while(true)
    {
        if(q[i]==1)
        break;
        i++;//找出第一位数是哪个
    }
    int j=p[0];
    while(j&&i)
    {
        cout<<i<<" "<<j<<" ";
        i=p[i];//i就等于了i之后俩位的数
        j=p[j];//j就等于了j之后俩位的数
    }
    if(i)
    cout<<i;//判断奇数还是偶数
    //就是这样子,喵~
    return 0;
}
时间: 2024-08-30 09:55:54

Codeforces Round #279 (Div. 2) B - Queue 水题的相关文章

Codeforces Round #256 (Div. 2/A)/Codeforces448A_Rewards(水题)解题报告

对于这道水题本人觉得应该应用贪心算法来解这道题: 下面就贴出本人的代码吧: 1 #include<cstdio> 2 #include<iostream> 3 using namespace std; 4 5 int a[3],b[3]; 6 7 int main(void) 8 { 9 int n; 10 int need = 0; 11 int sum1 = 0,sum2 = 0; 12 for(int i=1;i<=3;++i){ 13 scanf("%d&q

Codeforces Round #279 (Div. 2)B. Queue(构造法,数组下标的巧用)

这道题不错,思维上不难想到规律,但是如何写出优雅的代码比较考功力. 首先第一个人的序号可以确定,那么接下来所有奇数位的序号就可以一个连一个的确定了.然后a[i].first==0时的a[i].secod就是第二个人的序号,然后偶数位的序号也可以一个连一个的确定了. 用一个next数组,其下标就是a[i].first,其值就是a[i].second,这样巧妙地使用数组下标就解决了“串链子”这个难点,我之前想的每次用二分来找真是弱爆了.. 而在找第一个人的序号时也是妙用flag数组下标. #incl

Codeforces Round #196 (Div. 2) A. Puzzles 水题

A. Puzzles Time Limit: 2 Sec  Memory Limit: 60 MB 题目连接 http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemId=5373 Description The end of the school year is near and Ms. Manana, the teacher, will soon have to say goodbye to a yet another class. S

Codeforces Round #344 (Div. 2) C. Report 水题

#include<bits/stdc++.h> #define REP(i,a,b) for(int i=a;i<=b;i++) #define MS0(a) memset(a,0,sizeof(a)) #define rep(i,a,b) for(int i=a;i>=b;i--) #define RI(x) scanf("%d",&x) #define RII(x,y) scanf("%d%d",&x,&y) #d

Codeforces Round #256 (Div. 2/A)/Codeforces448A_Rewards(水题)

解题报告 意思就是说有n行柜子,放奖杯和奖牌.要求每行柜子要么全是奖杯要么全是奖牌,并且奖杯每行最多5个,奖牌最多10个. 直接把奖杯奖牌各自累加,分别出5和10,向上取整和N比較 #include <iostream> #include <cstdio> #include <cstring> #include <stdlib.h> #include <algorithm> #include <cmath> using namespa

水题 Codeforces Round #303 (Div. 2) D. Queue

题目传送门 1 /* 2 比C还水... 3 */ 4 #include <cstdio> 5 #include <algorithm> 6 #include <cstring> 7 #include <cmath> 8 #include <iostream> 9 using namespace std; 10 11 typedef long long ll; 12 13 const int MAXN = 1e5 + 10; 14 const i

Codeforces Round #279 (Div. 2) ABCD

Codeforces Round #279 (Div. 2) 做得我都变绿了! Problems # Name     A Team Olympiad standard input/output 1 s, 256 MB  x2377 B Queue standard input/output 2 s, 256 MB  x1250 C Hacking Cypher standard input/output 1 s, 256 MB  x740 D Chocolate standard input/

Codeforces Round #279 (Div. 2) b

/**  * @brief Codeforces Round #279 (Div. 2) b  * @file b.cpp  * @author mianma  * @created 2014/11/27 15:29  * @edited  2014/11/27 20:40  * @type   * @note  */ #include <cstdio> #include <stack> #include <cstring> #include <vector>

Codeforces Round #279 (Div. 2) a

/**  * @brief Codeforces Round #279 (Div. 2) a  * @file a.cpp  * @author 面码  * @created 2014/11/26 17:05  * @edited  2014/11/26 17:05  * @type   *  */ #include <cstdio> #include <stack> #include <cstring> using namespace std; #define max