社区讨论
三个点RE求大神指导
P1458[USACO2.1] 顺序的分数 Ordered Fractions参与者 3已保存回复 3
讨论操作
快速查看讨论及其快照的属性,并进行相关操作。
- 当前回复
- 3 条
- 当前快照
- 1 份
- 快照标识符
- @mi6h1jv7
- 此快照首次捕获于
- 2025/11/20 04:45 4 个月前
- 此快照最后确认于
- 2025/11/20 04:45 4 个月前
CPP
#include <iostream>
#include <cstdio>
#include <cmath>
#include <algorithm>
using namespace std;
struct ch{
int a;
int b;
}a[1000];
bool cmp1(ch m,ch r){
return m.a*r.b<m.b*r.a;
}
int gys(int q,int p){
if(p==0)
return q;
return gys(p,q%p);
}
int main() {
int n;
cin>>n;
int tot=1;
for(int i=0;i<=n;i++){
for(int j=1;j<=n;j++){
if(i<=j){
if(gys(j,i)==1){
a[tot].a=i;
a[tot].b=j;
tot++;
}
}
}
}
sort(a+1,a+tot,cmp1);
for(int i=1;i<=tot-1;i++){
cout<<a[i].a<<'/'<<a[i].b<<endl;
}
return 0;
}
回复
共 3 条回复,欢迎继续交流。
正在加载回复...