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=5时,只有两个blank,可我的出现了三个blank也AC了,下面附上我的代码

Posted by 1805180411 at 2013-01-09 15:50:51 on Problem 1313
#include<iostream>
#include<cmath>
#include<string>
using namespace std;

int n;
int m;
struct Paper
{
	int rightup,rightdown;
	int leftup,leftdown;
}paper[30];

void solve()
{
	int i;
	m = ceil(n/4.0);
	int s = 1;
	for(i = 1;i <= 2*m;i = i+2)
	{
		if(i <= n)
		   paper[s].rightup = i;
		if(i + 1 <= n)
		   paper[s].rightdown = i+1;
		s++;
	}
	s--;
	for(;i <= n;i = i+2)
	{
		
		paper[s].leftdown = i;
		if(i + 1 <= n)
		  paper[s].leftup = i+1;
		s--;
	}
/*
	for(i = 1;i <= m;i++)
		cout<<paper[i].rightup<<"  "<<paper[i].rightdown<<"  ";
	cout<<endl;
	i--;
	for(;i >= 1;i--)
		cout<<paper[i].leftdown<<"   "<<paper[i].leftup<<"  ";
*/
}
void output()
{
	int i ;
	cout<<"Printing order for "<<n<<" pages:"<<endl;
	for(i = 1;i <= m;i++)
	{
		cout<<"Sheet "<<i<<", front: ";
		if(paper[i].leftup == 0)
			cout<<"Blank";
		else
			cout<<paper[i].leftup;
		cout<<", ";
		if(paper[i].rightup == 0)
			cout<<"Blank";
		else
			cout<<paper[i].rightup;
		cout<<endl;
		if(paper[i].rightdown == 0 && paper[i].leftdown == 0)
			continue;
		cout<<"Sheet "<<i<<", back : ";
		if(paper[i].rightdown == 0)
			cout<<"Blank";
		else
			cout<<paper[i].rightdown;

		cout<<", ";
		if(paper[i].leftdown == 0)
			cout<<"Blank";
		else
			cout<<paper[i].leftdown;
		cout<<endl;

	}
}
int main()
{
	while(cin>>n && n)
	{
		memset(paper,0,sizeof(paper));
		solve();
		output();
	}
	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