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

Can I ask you for some testdata?My program is always wrong,but I can't find it!!!!!!

Posted by aniuan at 2014-08-05 11:05:14 on Problem 2947
#include <iostream> 
#include <cstring>
#include <string>
#include <cstdio> 
using namespace std;
const int maxn=500;
const int P=7;
int a[maxn][maxn],b[maxn];
int extend_gcd(int a,int b,int &x,int &y){
	if(b==0){x=1; y=0; return a;}
	int s,t;
	s=extend_gcd(b,a%b,x,y); t=x; x=y; y=t-a/b*y;
	return s;
}
void swap(int &x,int &y){
	int t;
	t=x; x=y; y=t; 
} 
int solve(int n,int m,int a[maxn][maxn],int b[maxn]){
	int i,k,p,col;
	for(k=col=0;col<n&&k<m;k++,col++){
		for(i=k;!a[i][col]&&i<m;i++);
		if(i==m){k--; continue;}
		for(p=col;p<n;p++) swap(a[i][p],a[k][p]);
		swap(b[i],b[k]);
		for(i=k+1;i<m;i++)if(a[i][col]){
			b[i]=(a[k][col]*b[i]-a[i][col]*b[k])%P; 
			for(p=n-1;p>=col;p--) a[i][p]=(a[k][col]*a[i][p]-a[i][col]*a[k][p])%P;
		} 
	} 
	for(i=k;i<m;i++) if(b[i]) return 0;
	if(k<n) return 1;
	for(k=n-1;k>=0;k--){
		int x,y;
		if(a[k][k]<0) a[k][k]=-a[k][k],b[k]=-b[k]; 
		extend_gcd(a[k][k],P,x,y);
		b[k]=(b[k]*x)%P;
		for(i=k-1;i>=0;i--)if(a[i][k]) b[i]=(b[i]-b[k]*a[i][k])%P;
	} 
	return 2;
}
int calc(char s[]){
	switch(s[0]){
		case 'M': return 1;
		case 'W': return 3;
		case 'T': if(s[1]=='U') return 2;
					else return 4;
		case 'F': return 5;
		case 'S': if(s[1]=='A') return 6;
					else return 7;
	}
}
int main(){
	int n,i,j,nn,m,x; 
	char c1[10],c2[10];
	while(scanf("%ld%ld\n",&n,&m)!=EOF&&(n||m)){
		memset(a,0,sizeof(a));
		memset(b,0,sizeof(b));
		for(i=0;i<m;i++){
			scanf("%ld %s %s\n",&nn,&c1,&c2);
			b[i]=(calc(c2)-calc(c1)+1+P)%P;
			for(j=0;j<nn;j++){
				scanf("%ld",&x);
				a[i][x-1]++;
				if(a[i][x-1]>P) a[i][x-1]-=P;
			}
			scanf("\n");
		}
		switch(solve(n,m,a,b)){
			case 0: printf("Inconsistent data.\n"); break;
			case 1: printf("Multiple solutions.\n"); break;
			case 2:
					for(i=0;i<n;i++) b[i]=(b[i]%P+P)%P;
					for(i=0;i<n-1;i++)
						if(b[i]<3) printf("%ld ",b[i]+P);
						else printf("%ld ",b[i]);
					if(b[n-1]<3) printf("%ld\n",b[n-1]+P);
					else printf("%ld\n",b[n-1]);
					break;
		}
	} 
	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