29 条题解
-
2qiuzili LV 8 @ 2017-10-04 22:00:34
写的跟屎一样。。。。
我也不知道我tm怎么会写出这种东西
那串0.00000000000001真是醉了#include<iostream> using namespace std; int A,B,a,b,l; double k,dk; int main() { cin>>A>>B>>l; k=double(A*1.0/B); dk=k+100; for(int i=1;i<=l;i++) for(int j=1;j<=l;j++) { if(double(i*1.0/j)-k<dk-0.00000000000001&&double(i*1.0/j)-k>=0) { a=i; b=j; dk=double(i*1.0/j)-k; } } cout<<a<<" "<<b; }
-
12021-08-30 09:19:37@
#include <bits/stdc++.h> using namespace std; int gcd(int x,int y) { if(y==0) return x; return gcd(y,x%y); } int main() { int i,j,a,b,ansa,ansb,l; cin>>a>>b>>l; ansa=l;ansb=1; for(i=1; i<=l; i++) for(j=1; j<=l; j++) if(gcd(i,j)==1 && i*b>=j*a && i*ansb<j*ansa){ ansa=i; ansb=j; } printf("%d %d",ansa,ansb); return 0; }
-
12019-09-13 19:28:05@
L最大100,可以暴力枚举。
#include <bits/stdc++.h> using namespace std; int main() { int a,b,l; cin>>a>>b>>l; int i,j,x,y; double gamma=100; double adb=1.0*a/b,idj; for(i=1;i<=l;i++) { for(j=1;j<l;j++) { idj=1.0*i/j; if(idj>=adb&&fabs(adb-idj)<gamma) { gamma=fabs(adb-idj); x=i; y=j; } } } cout<<x<<' '<<y<<endl; return 0; }
-
12017-10-29 11:47:31@
var
a,b,l,i,j,k,p:longint;
min:real;
begin
min:=10000000;
readln(a,b,l);
for i:=1 to l do begin
for j:=1 to l do begin
if (i/j>a/b) then begin
if (i/j)-(a/b)<min then begin
k:=i;
p:=j;
min:=(i/j)-(a/b);
end;
end;
end;
end;
writeln(k,' ',p);
end. -
12016-12-07 17:32:04@
var i,j,a,b,d,e,l:longint;c:real;
begin
read(a,b,l);
c:=maxlongint;
for i:=1 to l do
for j:=1 to l do
if (i/j>=a/b) and (i/j-a/b<c) then
begin
c:=i/j-a/b;
d:=i;
e:=j;
end;
write(d,' ',e);
end. -
12016-08-24 13:32:59@
var
a,b,l,i,j,k,p:longint;
min:real;
begin
min:=10000000;
readln(a,b,l);
for i:=1 to l do begin
for j:=1 to l do begin
if (i/j>a/b) then begin
if (i/j)-(a/b)<min then begin
k:=i;
p:=j;
min:=(i/j)-(a/b);
end;
end;
end;
end;
writeln(k,' ',p);
end. -
02020-04-12 23:49:03@
#include <iostream> //[2014普及组-B]比例简化 #include <algorithm> using namespace std; bool isPrime(int a, int b)//判断是否互质 { int t; while (b) { t = a % b; a = b; b = t; } if(a != 1) return false; return true; } int main() { int A, B, L, a = 0, b = 0; double k = 100000; cin >> A >> B >> L; for (int i = 1; i <= L; i++) for (int j = 1; j <= L; j++) if(i * B >= j * A && isPrime(i, j))//将除法比较转变为乘法比较,A/B ≤ L这个条件说明乘积不会过大 if (k > (double)i / j - (double)A / B) { k = (double)i / j - (double)A / B; a = i, b = j; } cout << a << " " << b << endl; return 0; }
-
02017-10-04 00:11:05@
在范围内一个个寻找比较即可。
#include <iostream>
using namespace std;double a, b, l;
double temp1, temp2, temp3;
double ans1, ans2;
double ans3 = 1e9;int identify(int c, int d) {
if (c > d) {
for (int k = 2; k <= d; k++) {
if ((c % k == 0) && (d % k == 0)) {
return 0;
}
}
} else {
for (int k = 2; k <= c; k++) {
if ((c % k == 0) && (d % k == 0)) {
return 0;
}
}
}
return 1;
}int main() {
cin >> a >> b >> l;
temp1 = a / b;
for (int i = 1; i <= l; i++) {
for (int j = 1; j <= l; j++) {
if (identify(i, j) == 1) {
temp2 = (double) i / j;
if (temp2 >= temp1) {
temp3 = temp2 - temp1;
if (temp3 < ans3) {
ans3 = temp3;
ans1 = i;
ans2 = j;
}
}}
}
}
cout << ans1 << ' ' << ans2;
return 0;
} -
02016-11-17 17:30:07@
//评测结果 编译成功 测试数据 #0: Accepted, time = 0 ms, mem = 564 KiB, score = 10 测试数据 #1: Accepted, time = 0 ms, mem = 560 KiB, score = 10 测试数据 #2: Accepted, time = 0 ms, mem = 560 KiB, score = 10 测试数据 #3: Accepted, time = 0 ms, mem = 560 KiB, score = 10 测试数据 #4: Accepted, time = 0 ms, mem = 560 KiB, score = 10 测试数据 #5: Accepted, time = 0 ms, mem = 560 KiB, score = 10 测试数据 #6: Accepted, time = 0 ms, mem = 560 KiB, score = 10 测试数据 #7: Accepted, time = 0 ms, mem = 556 KiB, score = 10 测试数据 #8: Accepted, time = 0 ms, mem = 560 KiB, score = 10 测试数据 #9: Accepted, time = 15 ms, mem = 560 KiB, score = 10 Accepted, time = 15 ms, mem = 564 KiB, score = 100 代码 #include<iostream> #include<stdio.h> using namespace std; int main() { double A,B,L,min=1<<30; cin>>A>>B>>L; double ta=1,tb=1; for(double i=1.0;i<=L;i++) for(double j=1.0;j<=L;j++) { double a=i/j, b=A/B; double c=a-b; if(a>=b) if(c<min) { ta=i; tb=j; min=c; } } cout<<ta<<" "<<tb; return 0; }//
-
02016-11-17 17:29:02@
c++解法 其实用不着这么麻烦 更神奇的是不需要判断质数!!
测试数据 #0: Accepted, time = 0 ms, mem = 564 KiB, score = 10
测试数据 #1: Accepted, time = 0 ms, mem = 560 KiB, score = 10
测试数据 #2: Accepted, time = 0 ms, mem = 560 KiB, score = 10
测试数据 #3: Accepted, time = 0 ms, mem = 560 KiB, score = 10
测试数据 #4: Accepted, time = 0 ms, mem = 560 KiB, score = 10
测试数据 #5: Accepted, time = 0 ms, mem = 560 KiB, score = 10
测试数据 #6: Accepted, time = 0 ms, mem = 560 KiB, score = 10
测试数据 #7: Accepted, time = 0 ms, mem = 556 KiB, score = 10
测试数据 #8: Accepted, time = 0 ms, mem = 560 KiB, score = 10
测试数据 #9: Accepted, time = 15 ms, mem = 560 KiB, score = 10
Accepted, time = 15 ms, mem = 564 KiB, score = 100
代码
#include<iostream>
#include<stdio.h>
using namespace std;
int main()
{
double A,B,L,min=1<<30;
cin>>A>>B>>L;
double ta=1,tb=1;
for(double i=1.0;i<=L;i++)
for(double j=1.0;j<=L;j++)
{
double a=i/j, b=A/B;
double c=a-b;
if(a>=b)
if(c<min)
{
ta=i;
tb=j;
min=c;
}
}
cout<<ta<<" "<<tb;
return 0;
} -
02016-09-16 16:06:47@
#include<cstdio>
typedef long long ll;
using namespace::std;
int Gcmp(int a,int b,int c,int d){ //比较a/b和c/d的大小
if((a*d)>(c*b)){return 1;}
if((a*d)==(c*b)){return 0;}
if((a*d)<(c*b)){return -1;}
}int main()
{
int a,b,c;
int ansa=a,ansb=1;
scanf("%d%d%d",&a,&b,&c);
for(int ia=c;ia>=1;ia--){
for(int ib=c;ib>=1;ib--){
int i=Gcmp(ia,ib,a,b);
if(i==1||i==0){
int l=Gcmp(ia,ib,ansa,ansb);
if(l==-1||l==0){
ansa=ia;
ansb=ib;
}
}
}
}
printf("%d %d",ansa,ansb);
return 0;
} -
02015-11-06 19:31:41@
评测结果
编译成功测试数据 #0: Accepted, time = 15 ms, mem = 276 KiB, score = 10
测试数据 #1: Accepted, time = 15 ms, mem = 272 KiB, score = 10
测试数据 #2: Accepted, time = 0 ms, mem = 276 KiB, score = 10
测试数据 #3: Accepted, time = 15 ms, mem = 272 KiB, score = 10
测试数据 #4: Accepted, time = 0 ms, mem = 272 KiB, score = 10
测试数据 #5: Accepted, time = 15 ms, mem = 272 KiB, score = 10
测试数据 #6: Accepted, time = 15 ms, mem = 276 KiB, score = 10
测试数据 #7: Accepted, time = 15 ms, mem = 276 KiB, score = 10
测试数据 #8: Accepted, time = 15 ms, mem = 276 KiB, score = 10
测试数据 #9: Accepted, time = 15 ms, mem = 272 KiB, score = 10
Accepted, time = 120 ms, mem = 276 KiB, score = 100
代码
#include<iostream>
#include<math.h>
#include<fstream>
using namespace std;
int prime(int x,int y)
{
int i,j;
for(i=2;i<=x;i++)
{
if(x%i==0)
for(j=2;j<=y;j++)
if(y%j==0&&j==i)
return 0;
}
return 1;
}
int main()
{
float a,b,l,c,k,i,j,min1=9999,f,g;
cin>>a>>b>>l;
c=a/b;
for(i=1.0;i<=l;i++)
for(j=1.0;j<=l;j++)
{
k=i/j;
if(prime(i,j)==1&&k>=c&&k<min1)
{
min1=k;
f=i;
g=j;
}
}
cout<<f<<" "<<g;
return 0;
} -
02015-10-25 15:37:16@
没有那么麻烦
program sajkdhjk;
var i,j,a,b,d,e,l:longint;c:real;
begin
read(a,b,l);
c:=maxlongint;
for i:=1 to l do
for j:=1 to l do
if (i/j>=a/b) and (i/j-a/b<c) then
begin
c:=i/j-a/b;
d:=i;
e:=j;
end;
write(d,' ',e);
end. -
02015-10-15 15:27:21@
var a,b,l,i,j,min_a,min_b:longint;
min:real;
function g(a,b:longint):longint;
begin
if a<b then begin a:=a+b; b:=a-b; a:=a-b; end;
if b=0 then g:=a;
else g:=g(b,a mod b);
end;begin
read(a,b,l);
min:=maxlongint;
min_a:=0;
min_b:=0;
if a=b then writeln('1 1')
else
begin
for i:=1 to l do
for j:=1 to l do
if (i/j>=a/b) and (g(i,j)=1) and (i/j-a/b<min) then
begin min:=i/j-a/b; min_a:=i; min_b:=j; end;
writeln(min_a,' ',min_b);
end;
end. -
02015-10-13 21:51:31@
var
a,b,l,i,j,mini,minj:longint;
r1,r2,min:real;
temp:1..1000;
begin
read(a,b,l);
r1:=a/b;
min:=maxlongint;
for i:=1 to l do
begin
for j:=1 to l do
begin
r2:=i/j;
if(r2-r1>1e-8)and(r2-r1-min<-(1e-8))then
begin
min:=r2-r1;
mini:=i;
minj:=j;
end;
end;
end;
writeln(mini,' ',minj);
end. -
02015-10-12 08:18:08@
#include<iostream>
using namespace std;
double a,b,aa,bb,l;
int gcd(int a,int b){return b==0?a:gcd(b,a%b);}
int main()
{
cin>>a>>b>>l;
double ans=a/b;
double ans2=0.0000;
double ans3=1000000.00;
for(double i=1.0;i<=l;i++)
{
for(double j=1.0;j<=l;j++)
{
ans2=(double)i/j;
double ans4=ans2-ans;
if(ans4>=0&&gcd((int)i,(int)j)==1&&ans4<=ans3){ans3=ans4;aa=i;bb=j;}
}
}
cout<<aa<<" "<<bb<<endl;
return 0;
} -
02015-10-05 15:51:29@
program NOIP1402;
VAR a,b,len,x,i,j,x1,x2:longint; m,n,ans:double;
function zzxc(a,b:longint):longint;
begin
if b=0 then exit(a) else exit(zzxc(b,a mod b));
end;procedure main;
var i,j,x,t1,t2:longint;
begin
for i:=1 to len do
for j:=1 to len do begin
x:=zzxc(i,j);
t1:=i div x;
t2:=j div x;
n:=t1/t2;
if (n>m) and ((n-m)<ans) then begin
ans:=n-m; x1:=t1; x2:=t2; end;
end;
end;BEGIN
read(a,b,len);
x:=zzxc(a,b);
a:=a div x;
b:=b div x;
ans:=maxlongint;
if (a<=len) and (b<=len) then begin
writeln(a,b); exit; end;
m:=a/b;
main;
writeln(x1,' ',x2);
end. -
02015-08-17 15:18:03@
#include <iostream>
#include <cstdio>
#include <algorithm>
using namespace std;
int a1,b1,l,k,p,minx,miny;
bool t;
double a,b,i,j,ab,mini;
int gcd(int a,int b) {return b?gcd(b,a%b):a;}int main()
{
cin >>a>>b>>l;
ab=(double)a/(double)b;
mini=214748;
for (i=1;i<=l;i++)
for (j=1;j<=l;j++)
if ((double)i/(double)j>=ab && (double)i/(double)j-ab<mini)
{
minx=i;
miny=j;
mini=(double)i/(double)j-ab;
}
while (minx%2==0 && miny%2 ==0)
{
minx/=2;miny/=2;
}
cout <<minx<<' '<<miny;
} -
02015-02-05 19:20:40@
编译成功
测试数据 #0: Accepted, time = 0 ms, mem = 744 KiB, score = 10
测试数据 #1: Accepted, time = 0 ms, mem = 744 KiB, score = 10
测试数据 #2: Accepted, time = 0 ms, mem = 748 KiB, score = 10
测试数据 #3: Accepted, time = 0 ms, mem = 744 KiB, score = 10
测试数据 #4: Accepted, time = 0 ms, mem = 744 KiB, score = 10
测试数据 #5: Accepted, time = 0 ms, mem = 740 KiB, score = 10
测试数据 #6: Accepted, time = 0 ms, mem = 744 KiB, score = 10
测试数据 #7: Accepted, time = 0 ms, mem = 740 KiB, score = 10
测试数据 #8: Accepted, time = 0 ms, mem = 740 KiB, score = 10
测试数据 #9: Accepted, time = 0 ms, mem = 740 KiB, score = 10
Accepted, time = 0 ms, mem = 748 KiB, score = 100
代码
var
i,j,l,n,m,x,zong,y:longint;
r:real;
beginreadln(x,y,l); zong:=0;
r:=maxlongint;
for i:=1 to l do
for j:=1 to l do
begin
if (i/j>=x/y)and(i/j-x/y<r)then begin r:=i/j-x/y;n:=i;m:=j; end;
end;
writeln(n,' ',m);
readln;end.//**虽然短,但速度很快
-
02015-01-14 13:30:50@
什么都跪了。。
var a,b,l,i,j,ans1,ans2:longint;
tmp1,tmp2,tmp3:real;
function gcd(a,b:longint):longint;
begin
if a mod b=0 then gcd:=b
else gcd:=gcd(b,a mod b);
end;
begin
readln(a,b,l);
tmp1:=a/b;
tmp3:=1000000;
for i:=1 to l do
begin
for j:=1 to l do
begin
tmp2:=i/j;
if (gcd(i,j)=1)and(tmp2>tmp1) then
begin
if tmp2-tmp1<tmp3 then
begin
ans1:=i;
ans2:=j;
tmp3:=tmp2-tmp1;
end;
end;
end;
end;
write(ans1,' ',ans2);
end.
信息
- ID
- 1912
- 难度
- 4
- 分类
- (无)
- 标签
- 递交数
- 2120
- 已通过
- 870
- 通过率
- 41%
- 被复制
- 12
- 上传者