1 solutions
-
0
模拟( 20pts)
- 根据题目要求去寻找合法解。
#include<bits/stdc++.h> using namespace std; int main() { int k; cin>>k; while(k--) { int n,e,d; cin>>n>>e>>d; int p,q; bool st=false; for(p=1;p<=n;p++) { for(q=p;q<=n;q++) { if(n==p*q&&e*d==(p-1)*(q-1)+1) //找到一组合法方案 { st=true; break; } } if(st) //找到了方案 { break; } } if(st) //有解 { cout<<p<<" "<<q<<endl; } else //无解 { cout<<"NO"<<endl; } } return 0; }
构造(100pts)
- 通过整理易得表达式是一个一元二次方程的解,我们直接带入求解答案。
#include<bits/stdc++.h> using namespace std; typedef long long LL; int main() { int k; cin>>k; while(k--) { LL n,d,e; cin>>n>>d>>e; LL m=n-e*d+2; //整理得 p^2-mq+n=0 LL det=m*m-4*n; LL r=sqrt(det); if(det>=0&&r*r==det) { cout<<(m-r)/2<<" "<<(m+r)/2<<endl; } else { cout<<"NO"<<endl; } } return 0; }
- 1
Information
- ID
- 1076
- Time
- 1000ms
- Memory
- 256MiB
- Difficulty
- 10
- Tags
- # Submissions
- 2
- Accepted
- 1
- Uploaded By