怎样优化?
查看原帖
怎样优化?
942429
hpsnail2013楼主2024/4/7 21:59

样例已过,只有40。求大佬指点优化。 感谢不已!

#include <iostream>

/* run this program using the console pauser or add your own getch, system("pause") or input loop */
using namespace std;
int main(int argc, char** argv) {
	int n,m;
	cin>>n>>m;
	long long zfx=0;
	long long cfx=0;
	for(int x1=0;x1<=n-1;x1++)
	{
		for(int y1=0;y1<=m-1;y1++)
		{
			for(int x2=x1+1;x2<=n;x2++)
			{
				for(int y2=y1+1;y2<=m;y2++)
				{
					int k=x2-x1;
					int j=y2-y1;
					if(k==j){
						zfx++;
					}
					else{
						cfx++;
					}
				}
			}
		}
	}
	cout<<zfx<<" "<<cfx;
	return 0;
}

https://www.luogu.com.cn/record/154827116

2024/4/7 21:59
加载中...