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

C++ AC,131ms, 特殊数据可过, 代码有些乱

Posted by kvsl at 2017-06-29 18:01:14 on Problem 1006
#include <iostream>
#include <queue>
using namespace std;
typedef struct{
	int num;
	int add;
}case_type;
bool inline firstMin(case_type&,case_type&,case_type&);
bool operator ==(const case_type& x, const case_type&y){
	return x.num == y.num;
}
case_type operator ++(case_type& x){
	x.num += x.add;
	return x;
}
int main(int argc, char** argv){
	queue<int*> qi;
	case_type p,e,i;
	int *temp;
	int result;

	p.add=23; e.add=28; i.add=33;
	int a,b,c,d;
	while(cin>>a>>b>>c>>d){
		if(a==-1 && b==-1 && c==-1 && d==-1)
			break;
		temp = new int[4];
		temp[0]=a; temp[1]=b; temp[2]=c; temp[3]=d;
		qi.push(temp);
	}
	int *back;
	int n=0;
	while(!qi.empty()){
		n++;
		back = qi.front();
		qi.pop();
		p.num=back[0];
		e.num=back[1];
		i.num=back[2];
		result=back[3];
		if(p==e && e==i && i==p && p.num==result)
			++p; ++e; ++i;

		while(!(p==e && e==i && p==i && p.num > result)){
			firstMin(p,e,i);
		}
		if(p.num-result > 21252)
			result = p.num-21252-result;
		else
			result = p.num-result;
		cout<<"Case "<<n<<": the next triple peak occurs in "<<result<<" days. "<<endl;
	}
	return 0;
}
bool firstMin(case_type& x, case_type& y, case_type& z){
	if(x==y && y==z && z==x){
		return true;
	}
	if((x.num <= y.num && x.num < z.num) || (x.num < y.num && x.num <= z.num)){
		++x;
		return false;
	}
	else if((y.num <= z.num && y.num < x.num)||(y.num < z.num && y.num <= x.num)){
		++y;
		return false;
	}
	else if((z.num <= x.num && z.num < y.num)||(z.num < x.num && z.num <=y.num)){
		++z;
		return false;
	}
}

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