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

hacker cup 2015 资格赛

时间:2015-01-21 19:35:26      阅读:177      评论:0      收藏:0      [点我收藏+]

标签:

A:交换一个数的两位,问能得到最大和最小的数是多少。

水题:

技术分享
 1 // File Name: a.cpp
 2 // Author: darkdream
 3 // Created Time: 2015年01月10日 星期六 17时16分44秒
 4 
 5 #include<vector>
 6 #include<list>
 7 #include<map>
 8 #include<set>
 9 #include<deque>
10 #include<stack>
11 #include<bitset>
12 #include<algorithm>
13 #include<functional>
14 #include<numeric>
15 #include<utility>
16 #include<sstream>
17 #include<iostream>
18 #include<iomanip>
19 #include<cstdio>
20 #include<cmath>
21 #include<cstdlib>
22 #include<cstring>
23 #include<ctime>
24 #define LL long long
25 
26 using namespace std;
27 LL a[20];
28 int T;
29 LL SP(LL i , LL j, LL tmp)
30 {
31      int x =(tmp)/a[i] % 10 ; 
32      int y =(tmp)/a[j] % 10 ;
33      if(x == 0 && j == T)
34          return tmp;
35      return tmp - x * a[i] - y*a[j] + y *a[i] + x*a[j]; 
36 }
37 int count(LL tmp)
38 {
39   int num = 0 ; 
40    while(tmp)
41    {
42      num ++;
43      tmp/= 10;
44    }
45    return num ;
46 }
47 int main(){
48    int t ;
49    scanf("%d",&t);
50    a[1] = 1; 
51    for(int i = 2;i <= 13 ;i++)
52    {
53      a[i] = a[i-1]*10;
54    }
55    for(int ca = 1 ; ca <= t ;ca ++)
56    {
57       LL tmp;
58       scanf("%lld",&tmp);
59       LL mx = tmp;
60       LL mi = tmp;
61       T = count(tmp);
62       for(int i = 1;i <= T;i ++)
63           for(int j = i + 1;j <= T ;j ++)
64           {
65             LL now = SP(i,j,tmp);
66             if(now > mx)
67                 mx = now;
68             if(now < mi)
69                 mi = now;
70           }
71       printf("Case #%d: %lld %lld\n",ca,mi,mx);
72    }
73 
74 return 0;
75 }
View Code

 

B:给你n件物品,每个物品都有三种属性值,问从中选取任意件,能不能使得最后得到确定值

解题思路:二进制枚举

解题代码:

技术分享
 1 // File Name: b.cpp
 2 // Author: darkdream
 3 // Created Time: 2015年01月10日 星期六 17时55分37秒
 4 
 5 #include<vector>
 6 #include<list>
 7 #include<map>
 8 #include<set>
 9 #include<deque>
10 #include<stack>
11 #include<bitset>
12 #include<algorithm>
13 #include<functional>
14 #include<numeric>
15 #include<utility>
16 #include<sstream>
17 #include<iostream>
18 #include<iomanip>
19 #include<cstdio>
20 #include<cmath>
21 #include<cstdlib>
22 #include<cstring>
23 #include<ctime>
24 #define LL long long
25 
26 using namespace std;
27 int Ga,Gb,Gc;
28 int a[30],b[30],c[30];
29 bool solve(int k)
30 {
31    int t= 0 ; 
32    int ta,tb,tc;
33    ta = tb = tc = 0 ; 
34    while(k)
35    {
36       if(k % 2)
37       {
38         ta += a[t];
39         tb += b[t];
40         tc += c[t];
41       }
42       k /= 2;
43       t ++ ; 
44    }
45   //<F5> printf("%d %d %d\n",ta,tb,tc);
46    if(ta == Ga && tb == Gb&& tc == Gc)
47    {
48        return  1;
49    }
50    return 0 ; 
51 }
52 int main(){
53   int T;
54   scanf("%d",&T);
55   for(int ca = 1;ca <= T; ca ++)
56   {
57       scanf("%d %d %d",&Ga,&Gb,&Gc);
58       int n;
59       scanf("%d",&n);
60       for(int i= 0;i < n;i++)
61       {
62         scanf("%d %d %d",&a[i],&b[i],&c[i]);
63       }
64       int total = (1 << n)-1;
65       int ok = 0 ; 
66       for(int i =0 ;i <= total;i ++)
67       {
68          if(solve(i))
69          {
70            ok = 1; 
71            break;
72          }
73       }
74       if(ok)
75         printf("Case #%d: yes\n",ca);
76       else printf("Case #%d: no\n",ca);
77   }
78 return 0;
79 }
View Code

 

C:给你一个网格图,其中每个网格中有墙,旋转的机关炮台,

hacker cup 2015 资格赛

标签:

原文地址:http://www.cnblogs.com/zyue/p/4239625.html

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