码迷,mamicode.com
首页 > 其他好文 > 详细

BOX (UVA-1587)

时间:2014-08-27 01:32:57      阅读:370      评论:0      收藏:0      [点我收藏+]

标签:style   blog   color   os   io   for   div   代码   log   

对比一下代码的书写差距:

我的代码:

 1 #include<iostream>
 2 
 3 using namespace std;
 4 
 5 int a[6];
 6 int b[6];
 7 int v[3];  //访问标记
 8 
 9 bool judge(int i, int j)
10 {
11     if(a[i]==a[j]&&b[i]==b[j])
12         return true;
13     return false;
14 }
15 
16 bool judge1()
17 {
18     if(a[v[0]]==a[v[1]])
19         if((b[v[0]]==b[v[2]]&&a[v[2]]==b[v[1]])||(b[v[0]]==a[v[2]]&&b[v[2]]==b[v[1]]))
20             return true;
21     else if(a[v[1]]==a[v[2]])
22         if((b[v[1]]==b[v[0]]&&a[v[0]]==b[v[2]])||(b[v[1]]==a[v[0]]&&b[v[2]]==b[v[0]]))
23             return true;
24     else if(a[v[0]]==a[v[2]])
25         if((b[v[1]]==b[v[0]]&&a[v[1]]==b[v[2]])||(b[v[1]]==a[v[0]]&&a[v[1]]==b[v[2]]))
26             return true;
27     else
28         return false;
29 }
30 
31 
32 int main()
33 {
34     while(scanf("%d%d", &a[0], &b[0]) != EOF)
35     {
36         if(a[0]<b[0])
37         {
38             int t;
39             t = a[0];
40             a[0]=b[0];
41             b[0]=t;
42         }
43         for(int i=1; i<6; i++)
44         {
45             int a0,b0;
46             cin>>a0>>b0;
47             if(a0<b0)
48             {
49                 int t = a0;
50                 a0 = b0;
51                 b0 = t;
52             }
53             a[i]=a0;
54             b[i]=b0;
55         }
56         int k,l,w = 0;
57         int flag = 0;
58         for(k=0; k<6; k++)
59         {
60             for(l=k+1; l<6; l++)
61             {
62                 if(judge(k,l))
63                 {
64                     v[w]=k;
65                     w++;
66                     a[l] = b[l] = flag--;
67                 }
68             }
69         }
70         if(judge1())
71             cout<<"POSSIBLE"<<endl;
72         else
73             cout<<"IMPOSSIBLE"<<endl;
74     }
75     return 0;
76 }

别人的代码:

 1 #include <cstdio>
 2 #include <cstdlib>
 3 #include <iostream>
 4 #include <iostream>
 5 #include <cstdio>
 6 #include <vector>
 7 #include <cstring>
 8 #include <cctype>
 9 #include <algorithm>
10 #include <cmath>
11 #include <cstdlib>
12 #include <queue>
13 #include <map>
14 #define maxn 100000 + 10
15 #define INF 0x7fffffff
16 using namespace std;
17 struct NODE
18 {
19     int h, w;
20     bool operator < (const NODE& rha) const{
21         if(h == rha.h) return w < rha.w;
22         return h < rha.h;
23     }
24 }a[10];
25 bool ok()
26 {
27     if(a[0].h != a[1].h || a[0].w != a[1].w) return false;
28     if(a[2].h != a[3].h || a[2].w != a[3].w) return false;
29     if(a[4].h != a[5].h || a[4].w != a[5].w) return false;
30     if(a[1].h != a[2].h) return false;
31     if(a[1].w != a[4].h) return false;
32     if(a[3].w != a[4].w) return false;
33     return true;
34 }
35 int main()
36 {
37     while(scanf("%d%d", &a[0].h, &a[0].w) != EOF)
38     {
39         if(a[0].h > a[0].w) swap(a[0].h, a[0].w);
40         for(int i = 1; i < 6; ++i)
41         {
42             scanf("%d%d", &a[i].h, &a[i].w);
43             if(a[i].h > a[i].w) swap(a[i].h, a[i].w);
44         }
45         sort(a, a+6);
46         if(ok()) puts("POSSIBLE");
47         else puts("IMPOSSIBLE");
48     }
49     return 0;
50 }

 

BOX (UVA-1587)

标签:style   blog   color   os   io   for   div   代码   log   

原文地址:http://www.cnblogs.com/chaiwentao/p/3938546.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!