USACO 2.1 Ordered Fractions

TASK: frac1
LANG: C++

Compiling...
Compile: OK

Executing...
   Test 1: TEST OK [0.000 secs, 3172 KB]
   Test 2: TEST OK [0.000 secs, 3172 KB]
   Test 3: TEST OK [0.000 secs, 3172 KB]
   Test 4: TEST OK [0.000 secs, 3172 KB]
   Test 5: TEST OK [0.000 secs, 3172 KB]
   Test 6: TEST OK [0.000 secs, 3172 KB]
   Test 7: TEST OK [0.000 secs, 3172 KB]
   Test 8: TEST OK [0.027 secs, 3172 KB]
   Test 9: TEST OK [0.162 secs, 3172 KB]
   Test 10: TEST OK [0.135 secs, 3172 KB]
   Test 11: TEST OK [0.243 secs, 3172 KB]

All tests OK.

YOUR PROGRAM ('frac1') WORKED FIRST TIME! That's fantastic -- and a rare thing. Please accept these special automated congratulations.

Here are the test data inputs:

------- test 1 ----
1
------- test 2 ----
2
------- test 3 ----
4
------- test 4 ----
7
------- test 5 ----
10
------- test 6 ----
15
------- test 7 ----
24
------- test 8 ----
50
------- test 9 ----
75
------- test 10 ----
100
------- test 11 ----
160
1 /*
2 ID: jiafeim1
3 PROG: frac1
4 LANG: C++
5 */
6 #include <iostream>
7 #include <fstream>
8 #include <algorithm>
9 #include <string>
10 #include <vector>
11 using namespace std;
12
13 #define maxN(x,y) ((x)>(y)?(x):(y))
14
15 bool huYue[164][164]={false};
16
17 struct num
18 {
19 int fenzi;
20 int fenmu;
21 double value;
22
23 bool operator < (const num& n1) const
24 {
25 return value<n1.value;
26 }
27 };
28
29 num res[7810];
30 int top = 0;
31 int main()
32 {
33 ofstream fout ("frac1.out");
34 ifstream fin ("frac1.in");
35
36 int n;
37 fin>>n;
38
39 for(int l = 2;l<=n/2;++l)
40 for(int i =l;i<=n-l;i+=l)
41 for(int j = i+l;j<=n;j+=l)
42 {
43 huYue[i][j] = true;
44 //huYue[j][i] = true;
45 }
46
47
48 for(int i =2;i<=n;++i)
49 for(int j=1;j<=i-1;++j)
50 {
51 if(!huYue[j][i])
52 {
53 res[top].fenmu = i;
54 res[top].fenzi = j;
55 res[top].value = ((double)j)/i;
56 ++top;
57 }
58 }
59 sort(res,res+top);
60 fout<<"0/1"<<endl;
61 for(int i = 0;i!=top;++i)
62 fout<<res[i].fenzi<<"/"<<res[i].fenmu<<endl;
63 fout<<"1/1"<<endl;
64 fin.close();
65 fout.close();
66 return 0;
67 }
posted @ 2011-05-03 11:52  幻魇  阅读(244)  评论(0编辑  收藏  举报