QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#625016#6422. Evil CoordinatetsaiCompile Error//C++147.0kb2024-10-09 17:10:192024-10-09 17:10:20

Judging History

你现在查看的是最新测评结果

  • [2024-10-09 17:10:20]
  • 评测
  • [2024-10-09 17:10:19]
  • 提交

answer

#include<bits/stdc++.h>
using namespace std;
typedef long long ll;

void solve(){
	int x0,y0;
	scanf("%d %d",&x0,&y0);
	int x=0,y=0;
	int up=0,down=0,left=0,right=0;
	string s;
	cin>>s;
	if(x0==0&&y0==0){
		printf("Impossible");
		return ;
	}
	int len=s.length();
	for(int i=0;i<len;i++){
		if(s[i]=='U'){
			up++;
			y++;
		}else if(s[i]=='D'){
			down++;
			y--;
		}else if(s[i]=='L'){
			left++;
			x--;
		}else{
			right++;
			x++;
		}
	}
	if(x==x0&&y==y0){
		printf("Impossible");
		return ;
	}else if(x!=x0&&y!=y0){
		int i=0;
		if(x0!=0){//(m,0)
			while(i<min(up,down)){
				printf("UD");
				i++;
			}
			int sub=max(up-i,down-i);
			if(up>i){
				while(sub){
					printf("U");
					sub--;
				}
			}else{//down
				while(sub){
					printf("D");
					sub--;
				}
			}
			//(0,yend),yend!=y0
			i=0;
			while(i<min(left,right)){
				printf("LR");
				i++;
			}
			sub=max(left-i,right-i);
			if(left>i){
				while(sub){
					printf("L");
					sub--;
				}
			}else{
				while(sub){
					printf("R");
					sub--;
				}
			}
		}else{//x==0,y!=0(0,n)
			i=0;
			while(i<min(left,right)){
				printf("LR");
				i++;
			}
			int sub=max(left-i,right-i);
			if(left>i){
				while(sub){
					printf("L");sub--;
				}
			}else{
				while(sub){
					printf("R");sub--;
				}
			}
			//(xend,0);xend!=x0
			i=0;
			while(i<min(up,down)){
				printf("UD");
				i++;
			}
			sub=max(up-i,down-i);
			if(up>i){
				while(sub){
					printf("U");
					sub--;
				}
			}else{//down
				while(sub){
					printf("D");
					sub--;
				}
			}
		}
	}else if(x==x0&&y!=y0){
		if(left==0&&right==0&&((y0>0&&y>y0)||(y0<0&&y<y0))){
			printf("Impossible");//横向不可调
			return ;
		}else{
			int i=0;
			if(y0==0){//x0!=0
				while(i<min(up,down)){
					printf("UD");
					i++;
				}
				int sub=max(up-i,down-i);
				if(up>i){
					while(sub){
						printf("U");sub--;
					}
				}else{
					while(sub){
						printf("D");sub--;
					}
				}
				//(0,m),y0==0
				while(left){
					printf("L");left--;
				}
				while(right){
					printf("R");right--;
				}
			}else if(y0>0){
				if(x0==0){//先拐弯
					//拐弯
					if(left>0){//也有可能l=r=0;y<y0
						printf("L");left--;
					}
					i=0;
					while(i<min(up,down)){
						printf("DU");
						i++;
					}
					int sub=max(up-i,down-i);
					if(down>i){
						while(sub){
							printf("D");sub--;
						}
					}else{
						while(sub){
							printf("U");sub--;
						}
					}
					//yend!=y0
					i=0;
					while(i<min(left,right)){
						printf("LR");
						i++;
					}
					sub=max(left-i,right-i);
					if(left>i){
						while(sub){
							printf("L");sub--;
						}
					}else{
						while(sub){
							printf("R");sub--;
						}
					}
				}else{
					while(i<min(up,down)){
						printf("UD");
						i++;
					}
					int sub=max(up-i,down-i);
					if(up>i){
						while(sub){
							printf("U");sub--;
						}
					}else{
						while(sub){
							printf("D");sub--;
						}
					}
					while(left){
						printf("L");left--;
					}
					while(right){
						printf("R");right--;
					}
				}
			}else{//y0<0
				if(x0==0){
					if(left>0){//也有可能l=r=0;y>y0
						printf("L");left--;
					}//拐弯
					i=0;
					while(i<min(up,down)){
						printf("UD");
						i++;
					}
					int sub=max(up-i,down-i);
					if(up>i){
						while(sub){
							printf("U");sub--;
						}
					}else{
						while(sub){
							printf("D");sub--;
						}
					}
					//yend!=y0
					i=0;
					while(i<min(left,right)){
						printf("LR");
						i++;
					}
					sub=max(left-i,right-i);
					if(left>i){
						while(sub){
							printf("L");sub--;
						}
					}else{
						while(sub){
							printf("R");sub--;
						}
					}
				}else{
					while(i<min(up,down)){
						printf("UD");
						i++;
					}
					int sub=max(up-i,down-i);
					if(up>i){
						while(sub){
							printf("U");sub--;
						}
					}else{
						while(sub){
							printf("D");sub--;
						}
					}
					while(left){
						printf("L");left--;
					}
					while(right){
						printf("R");right--;
					}
				}
			}
		}
	}else{//x!=x0&&y==y0
		if(up==0&&down==0((x0>0&&x>x0)||(x0<0&&x<x0))){
			printf("Impossible");//纵向不可调
			return ;
		}
		int i=0;
		if(x0==0){//y0!=0
			while(i<min(left,right)){
				printf("LR");
				i++;
			}
			int sub=max(left-i,right-i);
			if(left>i){
				while(sub){
					printf("L");sub--;
				}
			}else{
				while(sub){
					printf("R");sub--;
				}
			}
			//(m,0),x0==0
			while(up){
				printf("U");up--;
			}
			while(down){
				printf("D");down--;
			}
		}else if(x0>0){
			if(y0==0){
				//拐弯
				if(up>0){//也有可能u=d=0;x<x0
					printf("U");up--;
				}
				i=0;
				while(i<min(left,right)){
					printf("LR");
					i++;
				}
				int sub=max(left-i,right-i);
				if(left>i){
					while(sub){
						printf("L");sub--;
					}
				}else{
					while(sub){
						printf("R");sub--;
					}
				}
				//xend!=x0
				i=0;
				while(i<min(up,down)){
					printf("UD");
					i++;
				}
				sub=max(up-i,down-i);
				if(up>i){
					while(sub){
						printf("U");sub--;
					}
				}else{
					while(sub){
						printf("D");sub--;
					}
				}
			}else{
				i=0;
				while(i<min(left,right)){
					printf("LR");
					i++;
				}
				int sub=max(left-i,right-i);
				if(left>i){
					while(sub){
						printf("L");sub--;
					}
				}else{
					while(sub){
						printf("R");sub--;
					}
				}
				//xend!=x0
				i=0;
				while(i<min(up,down)){
					printf("UD");
					i++;
				}
				sub=max(up-i,down-i);
				if(up>i){
					while(sub){
						printf("U");sub--;
					}
				}else{
					while(sub){
						printf("D");sub--;
					}
				}
			}
		}else{//x0<0
		if(y0==0){
			//拐弯
			if(up>0){//也有可能up=down=0;x>x0
				printf("U");up--;
			}
			i=0;
			while(i<min(left,right)){
				printf("RL");
				i++;
			}
			int sub=max(left-i,right-i);
			if(right>i){
				while(sub){
					printf("R");sub--;
				}
			}else{
				while(sub){
					printf("L");sub--;
				}
			}
			//xend!=x0
			i=0;
			while(i<min(up,down)){
				printf("UD");
				i++;
			}
			sub=max(up-i,down-i);
			if(up>i){
				while(sub){
					printf("U");sub--;
				}
			}else{
				while(sub){
					printf("D");sub--;//最后这里拐回来
				}
			}
		}else{
			i=0;
			while(i<min(left,right)){
				printf("RL");
				i++;
			}
			int sub=max(left-i,right-i);
			if(right>i){
				while(sub){
					printf("R");sub--;
				}
			}else{
				while(sub){
					printf("L");sub--;
				}
			}
			//xend!=x0
			i=0;
			while(i<min(up,down)){
				printf("UD");
				i++;
			}
			sub=max(up-i,down-i);
			if(up>i){
				while(sub){
					printf("U");sub--;
				}
			}else{
				while(sub){
					printf("D");sub--;//最后这里拐回来
				}
			}
		}
		}
	}
}
int main(){
	int t=1;
	scanf("%d",&t);
	while(t--){
		solve();
		if(t) printf("\n");
	}
	return 0;
}

Details

answer.code: In function ‘void solve()’:
answer.code:255:34: error: expression cannot be used as a function
  255 |                 if(up==0&&down==0((x0>0&&x>x0)||(x0<0&&x<x0))){
      |                                 ~^~~~~~~~~~~~~~~~~~~~~~~~~~~~
answer.code:7:14: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
    7 |         scanf("%d %d",&x0,&y0);
      |         ~~~~~^~~~~~~~~~~~~~~~~
answer.code: In function ‘int main()’:
answer.code:427:14: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
  427 |         scanf("%d",&t);
      |         ~~~~~^~~~~~~~~