Problem:
Problem A:
Pi is Three
π
(spelled pi in English) is a mathematical constant representing the circumference of a circle whose di-
ameter is one unit length. The name
π
is said to come from the first letter of the Greek words περιφέρεια (meaning periphery) and περίμετρος (perimeter).
Recently, the government of some country decided to allow use of 3, rather than 3.14, as the approximate
value of π in school (although the decision was eventually withdrawn probably due to the blame of many
people). This decision is very surprising, since this approximation is far less accurate than those obtained
before the common era.
Ancient mathematicians tried to approximate the value of
π
without calculators. A typical method was
to calculate the perimeter of inscribed and circumscribed regular polygons of the circle. For example,
Archimedes (287–212 B.C.) proved that 223/71 <
π
< 22/7 using 96-sided polygons, where 223/71
and 22/7 were both accurate to two fractional digits (3.14). The resultant approximation would be more
accurate as the number of vertices of the regular polygons increased.
As you see in the previous paragraph,
π
was approximated by fractions rather than decimal numbers in
the older ages. In this problem, you are requested to represent
π
as a fraction with the smallest possible
denominator such that the representing value is not different by more than the given allowed error. If
more than one fraction meets this criterion, the fraction giving better approximation is preferred.
Input
The input consists of multiple datasets. Each dataset has a real number
R
(0 <
R
≤ 1) representing the
allowed difference between the fraction and
π
. The value may have up to seven digits after the decimal
point. The input is terminated by a line containing 0.0, which must not be processed.
Output
For each dataset, output the fraction which meets the criteria in a line. The numerator and denominator
of the fraction should be separated by a slash as shown in the sample output, and those numbers must be
integers.
Sample Input
0.15
0.05
0.0
Output for the Sample Input
3/1
19/6

Submitted solutions:

code_snippet: #include <bits/stdc++.h>
using namespace std;

int main(void){
  double d;
  while(cin >> d){
    if(abs(d) < 0.000000001) break;
    int den = -1, num = -1;
    for(int i = 1;;i++){
      double tmp = 20.0;
      for(int j = i*3;;j++){
        double frac = (double)j / (double)i;
        if(M_PI-d < frac && frac < M_PI+d){
          if( abs(M_PI - frac) < abs(M_PI - tmp) ){
            den = i; num = j;
            tmp = frac;
          }
        }
        if(M_PI+d < frac) break;
      }
      if(den != -1) break;
    }
    cout << num << "/" << den << endl;
  }
  return 0;
}
accuracy: 1
time_ms: 230
memory_kb: 3136
final_rank: 6

code_snippet: #include<iostream>
#include<sstream>
#include<algorithm>
#include<climits>
#include<cmath>
#include<cstdio>
#include<cstdlib>
#include<ctime>
#include<cfloat>
#include<functional>
#include<map>
#include<string>
#include<cstring>
#include<vector>
#include<queue>
#include<stack>
#include<deque>
#include<set>
#include<bitset>
#include<list>
#include<numeric>
#include<complex>

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> i_i;
typedef pair<long long, int> ll_i;
typedef pair<double, int> d_i;
typedef pair<long long, long long> ll_ll;
typedef pair<double, double> d_d;
typedef vector<int> Vint;

#define PI 3.141592653589793238462643383279
#define mod 1000000007LL
#define rep(i, n) for(i = 0;i < n;++i)
#define rep1(i, n) for(i = 1;i < n;++i)
#define rep2d(i, j, n) for(i = 0;i < n;++i)for(j = i + 1;j < n;++j)
#define per(i, n) for(i = n - 1;i > -1;--i)
#define int(x) int x; scanf("%d",&x)
#define int2(x, y) int x, y; scanf("%d%d",&x, &y)
#define int3(x, y, z) int x, y, z; scanf("%d%d%d",&x, &y, &z)
#define int4(v, x, y, z) int v, x, y, z; scanf("%d%d%d%d", &v, &x, &y, &z)
#define int5(v, w, x, y, z) int v, w, x, y, z; scanf("%d%d%d%d%d", &v, &w, &x, &y, &z)
#define scn(n, a) rep(i, n)cin >> a[i]
#define sc2n(n, a, b) rep(i, n)cin >> a[i] >> b[i]
#define pri(x) cout << x << "\n"
#define pri2(x, y) cout << x << " " << y << "\n"
#define pri3(x, y, z) cout << x << " " << y << " " << z << "\n"
#define pb push_back
#define mp make_pair
#define all(a) (a).begin(),(a).end()
#define endl "\n"
#define kabe puts("---------------------------")
#define kara puts("")
#define debug(x) cout << " --- " << x << "\n"
#define debug2(x, y) cout << " --- " << x << " " << y << "\n"
#define debug3(x, y, z) cout << " --- " << x << " " << y << " " << z << "\n"
#define X first
#define Y second
#define eps 0.000000001
#define prid(x) printf("%.15lf\n", x)


signed main(void){
  int i, j, k;
  for(int testcase = 0;testcase < 1234567;testcase++){
    for(;;){
      double d; cin >> d; if(d == 0.0)break;
      double t, b;
      bool fl = false;
      for(b = 1.0;!fl;b+=1.0){
        for(t = b * 3.0;t < b * 4.0;t+=1.0){
          if(PI - d <= t / b && t / b <= PI + d){
            fl = true;
            printf("%d/%d\n", (int)t, (int)b);
            break;
          }
        }
      }

    }

/*/

//*/ break;
  }
  return 0;
}
accuracy: 1
time_ms: 2740
memory_kb: 1208
final_rank: 7

code_snippet: #define _USE_MATH_DEFINES
#define INF 0x3f3f3f3f

#include <iostream>
#include <cstdio>
#include <sstream>
#include <cmath>
#include <cstdlib>
#include <algorithm>
#include <queue>
#include <stack>
#include <limits>
#include <map>
#include <string>
#include <cstring>
#include <set>
#include <deque>
#include <bitset>
#include <list>
#include <cctype>
#include <utility>
  
using namespace std;
  
typedef long long ll;
typedef pair <int,int> P;
typedef pair <int,P> PP;
  
static const double EPS = 1e-10;
  
static const int tx[] = {0,1,0,-1};
static const int ty[] = {-1,0,1,0};

bool equal(double lhs, double rhs){
  return (lhs - EPS <= rhs && rhs - EPS <= lhs);
}

int main(){
  double R;
  while(~scanf("%lf",&R)){
    if(equal(R,0.0)) break;
    for(int denominator = 1; denominator <= 10000000; denominator++){
      int upper = 10000000;
      int lower = 0;
      for(int round = 0; round < 30; round++){
        int mid = lower + (upper - lower)/2;
        if((double)mid/(double)denominator >= M_PI - R){
          upper = mid;
        }
        else{
          lower = mid;
        }
      }

      int numerator = upper;
      if((double)numerator/(double)denominator > M_PI + R) continue;

      printf("%d/%d\n",numerator,denominator);
      break;
    }
  }
}
accuracy: 1
time_ms: 20
memory_kb: 1200
final_rank: 3

code_snippet: #define _USE_MATH_DEFINES
#define INF 0x3f3f3f3f

#include <iostream>
#include <cstdio>
#include <sstream>
#include <cmath>
#include <cstdlib>
#include <algorithm>
#include <queue>
#include <stack>
#include <limits>
#include <map>
#include <string>
#include <cstring>
#include <set>
#include <deque>
#include <bitset>
#include <list>
#include <cctype>
#include <utility>
  
using namespace std;
  
typedef long long ll;
typedef pair <int,int> P;
typedef pair <int,P> PP;
  
static const double EPS = 1e-10;
  
static const int tx[] = {0,1,0,-1};
static const int ty[] = {-1,0,1,0};

bool equal(double lhs, double rhs){
  return (lhs - EPS <= rhs && rhs - EPS <= lhs);
}

int main(){
  double R;
  while(~scanf("%lf",&R)){
    if(equal(R,0.0)) break;
    for(int denominator = 1; denominator <= 10000000; denominator++){
      int upper = 10000000;
      int lower = 0;
      for(int round = 0; round < 30; round++){
        int mid = lower + (upper - lower)/2;
        if((double)mid/(double)denominator >= M_PI - R){
          upper = mid;
        }
        else{
          lower = mid;
        }
      }

      for(int numerator = upper; numerator <= 10000000; numerator++){
        if((double)numerator/(double)denominator > M_PI + R) break;
        printf("%d/%d\n",numerator,denominator);
        goto found;
      }
    }
  found:;
  }
}
accuracy: 1
time_ms: 20
memory_kb: 1204
final_rank: 4

code_snippet: #include <iostream>
#include <algorithm>
#include <cmath>
using namespace std;
#define EPS (1e-10)
#define EQ(a,b) (abs((a)-(b))<EPS)

const double PI=4*atan(1.0);

int main(){

    double r;
    while(cin>>r&&!EQ(r,0)){
        bool f=false;
        for(int i = 1; ; i++){
            for(int j = i*2; !(((double)j/i)>PI+r+EPS); j++){
                if(EQ(abs(((double)j/i)-PI),r)||abs(((double)j/i)-PI)<r){
                    f=true;
                    cout<<j<<"/"<<i<<endl;
                    break;
                }
            }
            if(f)
                break;
        }
    }
    return 0;
}
accuracy: 1
time_ms: 4020
memory_kb: 952
final_rank: 8

code_snippet: #include <iostream>
#include <cmath>
using namespace std;

int main(){
	double r;
	while(cin >> r , r != 0.0){
		pair<int,int> a(9999999,999999); 
		double pi = M_PI;

		for(int i = 1 ; i < 100000 ; i++){
			for(int k = -1 ; k < 2 ; k+=2){
				for(int j = 0 ; j < 2 ; j++){
					int nu = (int)( (pi+r*k) * i) + j;
					if(abs(nu - pi*i) <= r*i){
						a = min(a,make_pair(i,nu));
					}
				}
			}
		}
		cout << a.second << "/" << a.first << endl;
	}
}
accuracy: 1
time_ms: 140
memory_kb: 0
final_rank: 2

code_snippet: #include <iostream>
#include <cmath>
using namespace std;

int main(){
	double r;
	while(cin >> r , r != 0.0){
		pair<int,int> a(9999999,999999); 

		for(int i = 1 ; i < 100000 ; i++){
			for(int j = 0 ; j < 2 ; j++){
				int nu = (int)( (M_PI-r) * i) + j;
				if(abs(nu - M_PI*i) <= r*i){
					a = min(a,make_pair(i,nu));
				}
			}
		}
		cout << a.second << "/" << a.first << endl;
	}
}
accuracy: 1
time_ms: 60
memory_kb: 0
final_rank: 1

code_snippet: #include <iostream>
#include <cmath>

using namespace std;

int main()
{
  double r, u, v;
  bool f;

  while(cin>>r && r){
    f = true;

    for(int i = 1; i < 100000 && f; i++){
      for(int j = i*3; j < 100000 && f; j++){
	u = fabs(M_PI - (double)j/i);
	if(u <= r){
	  cout << j << "/" << i << endl;
	  f = false;
	} else if(j > i && (double)j/i > M_PI){
	  break;
	}
      }
    }
  }

  return 0;
}
accuracy: 1
time_ms: 490
memory_kb: 948
final_rank: 5