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

标程原来如此简单,只是复杂度高了许多!!但避免了精度问题!!

Posted by CSUST_14 at 2012-08-26 10:05:58 on Problem 2100
#include <fstream>
#include <vector>
#include <iostream>

using namespace std;

typedef __int64 lint;

//ifstream in("graveyard.in");
//ofstream out("graveyard.out");

vector<pair<lint, lint> > ans;

void outLint(lint const & l)
{
	char tmp[100];
	sprintf(tmp, "%I64d", l);
    cout <<tmp;
}

int main()
{
	char tmp[100];
    lint N;
    cin >> tmp;
	sscanf(tmp, "%I64d", & N);
    lint l = 1;
    lint r = 1;
    lint sum = 1;
    for (;l*l <= N;)
    {
        if (sum < N) ++r, sum += r*r;
        else
        {
            if (sum == N) ans.push_back(make_pair(l, r));
            sum -= l*l;
            ++l;
        }
    }

    cout <<ans.size()<<endl;
    for (int i = 0;i!=ans.size();++i)
    {
		outLint(ans[i].second-ans[i].first+1);
		cout <<' ';
        for (lint j = ans[i].first; j <=ans[i].second;++j)
		{
            outLint(j);
			cout<<' ';
		}
        cout <<endl;
    }

    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