QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#400639#6621. Luggage LockSiilhouetteCompile Error//C++141.5kb2024-04-27 14:33:132024-04-27 14:33:14

Judging History

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

  • [2024-04-27 14:33:14]
  • 评测
  • [2024-04-27 14:33:13]
  • 提交

answer

#define _CRT_SECURE_NO_WARNINGS
#include<set>
#include<cmath>
#include<queue>
#include<string>
#include<cstring>
#include<iostream>
#include<algorithm>
using namespace std;

char s1[10],s2[10];
int ans,a[10],b[10],c[10];

inline int sgn(int x)
{
	if(x>0)return 1;
	else if(x==0)return 0;
	else return -1;
}

inline void cal(int &res,int l,int r)
{
	/*
	cout<<"cal "<<l<<" "<<r<<endl;
	for(int i=l;i<=r;i++)
		cout<<a[i]<<" ";
	cout<<endl;
	*/
	if(l>r)return;
	int mini=1000000000;
	for(int i=l;i<=r;i++)
		mini=min(mini,a[i]);
	res+=mini;
	for(int i=l;i<=r;i++)
		a[i]-=mini;
	for(int i=l;i<=r;)
	{
		int j=i;
		if(!a[i]){ i++;continue; }
		while(j<r&&sgn(a[j+1])==sgn(a[i]))j++;
		cal(res,i,j);
		i=j+1;
	}
}

inline int sol()
{
	int res=0;
	for(int i=1;i<=4;)
	{
		if(!a[i]){ i++;continue; }
		int j=i;
		while(j<4&&sgn(a[j+1])==sgn(a[i]))j++;
		for(int k=i;k<=j;k++)
			a[k]=abs(a[k]);
		cal(res,i,j);
		i=j+1;
	}
	//cout<<res<<endl;
	return res;
}

int main()
{
	int T;
	scanf("%d",&T);
	for(int _=1;_<=T;_++)
	{
		scanf("%s%s",s1+1,s2+1);
		for(int i=1;i<=4;i++)
			a[i]=s1[i]-'0',b[i]=s2[i]-'0',a[i]=b[i]-a[i];
		for(int i=1;i<=4;i++)
			c[i]=a[i];
		ans=1000000000;
		//sol();
		
		for(int i=0;i<16;i++)
		{
			for(int j=0;j<4;j++)
			{
				if(i>>j&1)a[j+1]=c[j+1];
				else a[j+1]=sgn(c[j+1])*(-1)*(10-abs(c[j+1]));
			}
			//cout<<"i ";
			ans=min(ans,sol());
		}
		/**/
		if(_==73){printf("%s %s",s1+1,s2+1);
		printf("%d\n",ans);
	}
	return 0;
}


Details

answer.code: In function ‘int main()’:
answer.code:92:2: error: expected ‘}’ at end of input
   92 | }
      |  ^
answer.code:64:1: note: to match this ‘{’
   64 | {
      | ^
answer.code:66:14: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   66 |         scanf("%d",&T);
      |         ~~~~~^~~~~~~~~
answer.code:69:22: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   69 |                 scanf("%s%s",s1+1,s2+1);
      |                 ~~~~~^~~~~~~~~~~~~~~~~~