Chinaunix首页 | 论坛 | 博客
  • 博客访问: 590427
  • 博文数量: 197
  • 博客积分: 7001
  • 博客等级: 大校
  • 技术积分: 2155
  • 用 户 组: 普通用户
  • 注册时间: 2005-02-24 00:29
文章分类

全部博文(197)

文章存档

2022年(1)

2019年(2)

2015年(1)

2012年(100)

2011年(69)

2010年(14)

2007年(3)

2005年(7)

分类: C/C++

2012-01-31 22:06:49

SRM 531  DIV 2
只出了第一题

class UnsortedSequence{
public:
    vector getUnsorted(vector s){
        int i;
        vector ans;
        sort(s.begin(),s.end());
        int sz=s.size()-1;
        for(i=sz;i>=1;i--){
            if(s[i]>s[i-1]){
                int t=s[i-1];
                s[i-1]=s[i];
                s[i]=t;
                break;
            }
        }
        if(i==0)
            return ans;
        else
            return s;
    }
};

#include
#include
#include
#include
#include
using namespace std;

typedef long LL;
//typedef __int64 LL;

struct rang{
    LL high;
    LL z;
    rang(int a,int b):high(a),z(b){}
};
   
vector m[65537];
LL res[65537][3];

bool compr(const rang& a, const rang& b)
{
    if(a.high        return true;
    else
        return false;
}

int main()
{
    int i,j;
    int n,M;
   
    while(scanf("%d%d",&n,&M)!=EOF){
        int x,y,z;
        for(i=0;i            scanf("%d%d%d",&x,&y,&z);
            m[x].push_back(rang(y,z));
        }
        int cnt=0;
        for(i=1;i<=n;i++){
            if(!m[i].empty()){
                sort(m[i].begin(),m[i].end(),compr);
                res[cnt][0]=i;
                res[cnt][1]=m[i][0].high;
                res[cnt][2]=m[i][0].z;
                cnt++;
                int sz=m[i].size();
                for(j=1;j                    if(m[i][j].high==m[i][0].high){
                        if(m[i][j].z!=m[i][0].z){
                            printf("-1\n");
                            goto out;
                        }
                    }
                    else{
                        m[m[i][0].high+1].push_back(rang(m[i][j].high,m[i][j].z-m[i][0].z));
                    }
                   
                }
            }
        }
        for(i=cnt-1;i>=1;i--)
            for(j=i-1;j>=0;j--){
                if(res[j][1]

out:
        ;   
    }

 
    return 0;
}

阅读(975) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~