社区讨论

怎样优化?

P2241统计方形(数据加强版)参与者 2已保存回复 1

讨论操作

快速查看讨论及其快照的属性,并进行相关操作。

当前回复
1 条
当前快照
1 份
快照标识符
@lupldjnh
此快照首次捕获于
2024/04/07 22:01
2 年前
此快照最后确认于
2024/04/08 12:52
2 年前
查看原帖
样例已过,只有40。求大佬指点优化。 感谢不已!
CPP
#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

回复

1 条回复,欢迎继续交流。

正在加载回复...