社区讨论

60pts 本地跑过了

P8814[CSP-J 2022] 解密参与者 2已保存回复 1

讨论操作

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

当前回复
1 条
当前快照
1 份
快照标识符
@mhjauk0b
此快照首次捕获于
2025/11/03 23:33
4 个月前
此快照最后确认于
2025/11/03 23:33
4 个月前
查看原帖
subtask16:为什么本地跑没有“NO”但显示输出“NO”?
CPP
#include <bits/stdc++.h>

using namespace std;

#define int long long

inline int read(){
    char c=getchar();
    bool b=0;
    while(c<'0'||c>'9'){
        if(c=='-'){
            b=1;
        }
        c=getchar();
    }
    int res=0;
    while(c>='0'&&c<='9'){
        res=res*10+(c-'0');
        c=getchar();
    }
    if(b){
        return -res;
    }
    return res;
}

signed main(){
//	freopen("eg.txt","r",stdin); 
	int k=read();
	while(k--){
		int n=read(),d=read(),e=read();
		int a=1,b=(e*d-2-n),c=n;
		int derta=b*b-4*a*c;
		if(derta<0){
			cout<<"NO"<<'\n';
			continue;
		}
		double tmpt=sqrt(derta);
		if(tmpt!=(int)tmpt){
			cout<<"NO"<<'\n';
			continue;
		}
		int tmp=tmpt;
		double pt=(-b-tmp)/2;
		double qt=(-b+tmp)/2;
		if(pt<0||qt<0){
			cout<<"NO"<<'\n';
			continue;
		}
		if((int)pt!=pt||(int)qt!=qt){
			cout<<"NO"<<'\n';
			continue;
		}
		int p=pt,q=qt;
		cout<<p<<' '<<q<<'\n';
	}
    return 0;
}

回复

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

正在加载回复...