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

Re:为什么我的程序(本地)在G++下Sample1有问题,在VC下没问题,提交时WA?

Posted by sinkingship at 2006-02-19 20:59:48 on Problem 1009
In Reply To:为什么我的程序(本地)在G++下Sample1有问题,在VC下没问题,提交时WA? Posted by:sinkingship at 2006-02-19 20:58:35
> 郁闷
忘了copy程序
#include <vector>
#include <string>
#include <algorithm>
#include <cmath>
#include <iostream>
using namespace std;
#define max(a,b) ((a)>(b)?(a):(b))
struct RLNode{
	int data;
	int length;
	RLNode(){}
	RLNode( int d, int l ){ data = d; length = l; }
};
int width;
vector<RLNode> input;
vector<RLNode> output;
int i , j ;
vector<int> rescache1, rescache2;
vector<int> linecache1, linecache2;
void getline( vector<int>& ret ){
	for(int k=0;k<width;k++){
		ret[k] = input[i].data;
		j++;
		if(j>=input[i].length){
			i++;
			j=0;
		}
	}
}
void push( const vector<int>& s ){
	for(int k=0;k<s.size();){
		int cnt = 1;
		while(cnt<s.size() && s[k]==s[k+cnt]) cnt++;
		output.push_back( RLNode(s[k],cnt) );
		k+=cnt;
	}
}
void simplify(){
	for(int k=1;k<output.size();k++) if( output[k].data == output[k-1].data ){
		output[k-1].length+=output[k].length;
		output.erase( output.begin()+k );
		k--;
	}
}
void answer(){
	cout<<width<<endl;
	for(int i=0;i<output.size();i++){
		cout<<output[i].data<<' '<<output[i].length<<endl;
	}
	cout<<"0 0"<<endl;
}
void work(){
	i = j = 0;
	rescache1.resize(width);
	rescache2.resize(width);
	linecache1.resize(width);
	linecache2.resize(width);
	bool pre = false;
	vector<int>* prline = &linecache1, *line = &linecache2;
	vector<int>* last = &rescache1, *now = &rescache2;
	while(1){
		if(i>=input.size()) break;
		if(j>=width && input[i].length-j>=width*2) {
			push(*last);
			int x = (input[i].length-j-width)/width*width;
			output.push_back( RLNode(0, x) );
			j += x;
			pre = false;
			continue;
		}
		getline(*line);
		fill( (*now).begin(), (*now).end(), (int)0 );
		for(int k=0;k<width;k++) {
			if(pre){
				(*now)[k] = max( abs( (*prline)[k]-(*line)[k] ) , (*now)[k] );
				(*last)[k] = max( abs( (*prline)[k]-(*line)[k] ) ,  (*last)[k] );
				if(k>0){
					(*now)[k] = max( abs( (*prline)[k-1]-(*line)[k] ), (*now)[k] );
					(*last)[k-1] = max( abs( (*prline)[k-1]-(*line)[k] ), (*last)[k-1] );
				}
			}
			if(k>0){
				(*now)[k] = max( abs( (*line)[k]-(*line)[k-1] ) , (*now)[k] );
				(*now)[k-1] = max( abs( (*line)[k]-(*line)[k-1] ) ,  (*now)[k-1] );
			}
		}
		if(pre) push(*last);
		swap(last, now);
		swap(prline,line);
		pre = true;
	}
	push(*last);
	simplify();
	answer();
}
int main(){
	while(1){
		cin>>width;
		if(width<=0) {
			cout<<0<<endl;
			break;
		}
		input.clear();
		int c, l;
		while(1){
			cin>>c>>l;
			if(c==0) break;
			input.push_back( RLNode(c,l) );
		}
		output.clear();
		work();
	}
	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