如何优化?
查看原帖
如何优化?
977778
__Harry_Haiyun__楼主2023/9/9 13:34
#include <bits/stdc++.h>
#define int long long
#define iostream() ios::sync_with_stdio(false),cin.tie(NULL),cout.tie(NULL);
using namespace std;
const int maxn = 1e6+7;
const int MAXN = maxn / 2;
signed main()
{
    iostream();
    int n,x,y;
    cin >> n;
    while (n--)
    {
    	cin >> x >> y;
    	Run1:
	    	for (int i = 0;; i++)
	    	{
	    		for (int j = 0;; j++)
	    		{
	    			for (int k = 0;; k++)
	    			{
	    				if (i + j + k == x && i * 2 + j * 3 + k * 4 == y)
	    				{
	    					cout << k << ' ';
	    					goto Run2;
						}
					}
				}
			}
		Run2:
			for (int i = y / 2; i > 0; i--)
			{
				for (int j = y / 3; j > 0; j--)
				{
					for (int k = y / 4; k > 0; k--)
					{
						if (i + j + k == x && i * 2 + j * 3 + k * 4 == y)
						{
							cout << k << '\n';
							goto Go_Back_To_Fortran;
						}
					}
				}
			}
		Go_Back_To_Fortran:
			x = 0,y = 0;
	}
 	return 0;
}
2023/9/9 13:34
加载中...