码迷,mamicode.com
首页 > 其他好文 > 详细

cf976d Degree Set

时间:2018-05-03 22:05:30      阅读:119      评论:0      收藏:0      [点我收藏+]

标签:article   return   ret   algo   second   ack   href   mes   using   

ref

#include <algorithm>
#include <iostream>
#include <cstdio>
#include <vector>
using namespace std;
int n, d[305], deg[1005];
vector<pair<int,int> > vec;
int main(){
    cin>>n;
    for(int i=1; i<=n; i++)
        scanf("%d", &d[i]);
    int l=1, r=n, q=d[n]+1, lst=0;
    for(int i=1; i<=q; i++){
        if(l<=r && q-i+deg[i]==d[r]){
            lst = 1;
            r--;
        }
        else if(l<=r && deg[i]==d[l]){
            lst = 0;
            l++;
        }
        if(lst){
            for(int j=i+1; j<=q; j++){
                deg[i]++; deg[j]++;
                vec.push_back(make_pair(i,j));
            }
        }
    }
    cout<<vec.size()<<endl;
    for(int i=0; i<vec.size(); i++)
        printf("%d %d\n", vec[i].first, vec[i].second);
    return 0;
}

cf976d Degree Set

标签:article   return   ret   algo   second   ack   href   mes   using   

原文地址:https://www.cnblogs.com/poorpool/p/8987355.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!