如果发现广告等破坏行为,请尽量将条目恢复到较早的版本而不是把相应内容直接删除,谢谢合作。

URAL/1303

来自"NOCOW"

跳转到: 导航, 搜索
#include <iostream>
using namespace std;
int x,r,i,j,a[5010],l[5010],m,now=0,tot=0;
int main()
{
    cin >> m;
    for (i=1;i<=m;++i)  l[i]=m;
    do
    {
        cin >> i >> j;
        if (j <= 0)  continue;
        if (j > m)  x=m;
        else  x=j;
        if (i < l[x])
        {
            l[x]=i;
            if (x == m)  r=j;
        }
    }while (i || j);
    do
    {
        x=m;
        while (l[x] > now)  --x;
        if (x == now)
        {
            cout << "No solution" << endl;
            return 0;
        }
        a[++tot]=now=x;
    }while (now != m);
    cout << tot << endl;
    for (int i=1;i<=tot;++i)
    {
        cout << l[a[i]] << ' ';
        if (a[i] == m)  cout << r << endl;
        else  cout << a[i] << endl;
    }
    return 0;
}
//by zzy
个人工具