Online JudgeProblem SetAuthorsOnline ContestsUser
Web Board
Home Page
F.A.Qs
Statistical Charts
Problems
Submit Problem
Online Status
Prob.ID:
Register
Update your info
Authors ranklist
Current Contest
Past Contests
Scheduled Contests
Award Contest
User ID:
Password:
  Register

注意, n和m得用long long ~~

Posted by taozifish at 2011-08-11 21:12:39 on Problem 2085
#include<cstdio>
#include<iostream>
using namespace std;
int main(){
    long long n, m;               //n, m一定要定义成long long,WA了几次才发现
    int i, a[50005], b[50005];
    while(scanf("%lld%lld", &n, &m)&&n>0){
        int ia=0, ib=0;
        for(i=1; i<=n; i++){
            if(n-i<=m&&m>0&&(n-i-1)*(n-i)/2<m){
                m-=(n-i);
                b[ib++]=i;
            }
            else a[ia++]=i;
        }
        printf("%d", a[0]);
        for(i=1; i<ia; i++)
        printf(" %d", a[i]);
        for(i=ib-1; i>=0; i--)
        printf(" %d", b[i]);
        printf("\n");
    }
    return 0;
}

Followed by:

Post your reply here:
User ID:
Password:
Title:

Content:

Home Page   Go Back  To top


All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator