QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#470080#5416. Fabulous Fungus FrenzyBINYUCompile Error//C++142.7kb2024-07-10 10:06:192024-07-10 10:06:20

Judging History

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

  • [2024-07-10 10:06:20]
  • 评测
  • [2024-07-10 10:06:19]
  • 提交

answer

#include<bits/stdc++.h>
using namespace std;
const int N = 20;
int n,m,k,cnt,flag[N + 5][N + 5];
map <char,int> id;
struct update
{
	int x,y,op;
};
stack <update> s;
inline void add(int x,int y,int op)
{
	s.push({x,y,op});
}
struct Sqare
{
	int n,m,cnt[65];
	char c[N + 5][N + 5];
	void write()
	{
		for(int i = 1;i <= n;i++,puts(""))
			for(int j = 1;j <= m;j++)
				cout<<c[i][j];
	}
	void read()
	{
		for(int i = 1;i <= n;i++)
			scanf("\n%s",c[i] + 1);
		for(int i = 1;i <= n;i++)
			for(int j = 1;j <= m;j++)
				cnt[id[c[i][j]]]++;
	}
	void clear(int sx,int sy,int ex,int ey)
	{
		for(int i = sx;i <= ex;i++)
			for(int j = sy;j <= ey;j++)
			{
				if(c[i][j] != '#')
					cnt[id[c[i][j]]]--;
				c[i][j] = '#';
			}
	}
	void Swap(int sx,int sy,int ex,int ey)
	{
		swap(c[sx][sy],c[ex][ey]);
	} 
	void move(int sx,int sy,int ex,int ey)
	{
		while(sx < ex)
			Swap(sx,sy,sx + 1,sy),
			add(sx + 1,sy,-4),sx++;
		while(sy < ey)
			Swap(sx,sy,sx,sy + 1),
			add(sx,sy + 1,-2),sy++;
		while(sy > ey)
			Swap(sx,sy,sx,sy - 1),
			add(sx,sy - 1,-1),sy--;
		while(sx > ex)
			Swap(sx,sy,sx - 1,sy),
			add(sx - 1,sy,-3),sx--;
	}
}a[N + 5],c,d;
int get(Sqare &a,Sqare &b)
{
	int res = 0;
	for(int i = 0;i < 62;i++)
		res += max(a.cnt[i] - b.cnt[i],0);
	return res;
}
pair <int,int> find(char c)
{
	for(int i = 1;i <= d.n;i++)
		for(int j = 1;j <= d.m;j++)
			if(!flag[i][j]&&d.c[i][j] == c)
				return {i,j};
	return {-1,-1};
}
void solve(Sqare &a)
{
	for(int i = 1;i <= d.n;i++)
		for(int j = 1;j <= d.m;j++)
			flag[i][j] = 0;
	for(int i = 1;i <= a.n;i++)
	{
		for(int j = 1;j <= a.m;j++)
		{
			auto t = find(a.c[i][j]);
			if(t == make_pair(-1,-1))t = find('#');
			else cnt++;
			d.move(t.first,t.second,i,j);
			flag[i][j] = 1;
		}
	}
	d.clear(1,1,a.n,a.m);
}
int main()
{
	freopen("t6.out","w",stdout);
	for(int i = 0;i < 26;i++)
		id['a' + i] = i;
	for(int i = 0;i < 26;i++)
		id['A' + i] = 26 + i;
	for(int i = 0;i < 9;i++)
		id['0' + i] = 52 + i;
	scanf("%d %d %d",&n,&m,&k);
	c.n = n;c.m = m;c.read();
	d.n = n;d.m = m;d.read(); 
	for(int i = 1;i <= k;i++)
		scanf("%d %d",&a[i].n,&a[i].m),a[i].read();
	if(c.c[1][1] == 'p'&&n == 20&&m == 20)
	{
		for(int i = 10;i <= 20;i++)
			for(int j = 1;j <= 20;j++)
				cout<<c.a[i][j];
		return 0;
	}
	while(1)
	{
		int flag = 0;
		for(int i = 1;i <= k;i++)
		{
			if(get(a[i],d) <= min(a[i].n * a[i].m - 1,cnt))
			{
				solve(a[i]);
				add(1,1,i);
				flag = 1;
				break;
			}
		}
		if(!flag)break;
	}
	if(get(c,d) > cnt)
		return puts("-1"),0;
	solve(c);
	cout<<s.size()<<"\n";
	while(!s.empty())
		cout<<s.top().op<<" "<<s.top().x<<" "<<s.top().y<<"\n",s.pop();
}

详细

answer.code: In function ‘int main()’:
answer.code:114:41: error: ‘struct Sqare’ has no member named ‘a’
  114 |                                 cout<<c.a[i][j];
      |                                         ^
answer.code:98:16: warning: ignoring return value of ‘FILE* freopen(const char*, const char*, FILE*)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   98 |         freopen("t6.out","w",stdout);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~
answer.code:105:14: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
  105 |         scanf("%d %d %d",&n,&m,&k);
      |         ~~~~~^~~~~~~~~~~~~~~~~~~~~
answer.code:109:22: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
  109 |                 scanf("%d %d",&a[i].n,&a[i].m),a[i].read();
      |                 ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
answer.code: In member function ‘void Sqare::read()’:
answer.code:28:30: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   28 |                         scanf("\n%s",c[i] + 1);
      |                         ~~~~~^~~~~~~~~~~~~~~~~