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

BestCoder Round #8

时间:2014-09-08 00:55:56      阅读:327      评论:0      收藏:0      [点我收藏+]

标签:style   blog   color   os   io   ar   for   div   sp   

Summary

 1 /*
 2 ID:esxgx1
 3 LANG:C++
 4 PROG:bestcoder8_A
 5 */
 6 #include <cstdio>
 7 #include <cstring>
 8 #include <iostream>
 9 #include <algorithm>
10 using namespace std;
11 
12 int a[107];
13 long long b[107*107];
14 
15 int main(void)
16 {
17     #ifndef ONLINE_JUDGE
18     freopen("in.txt", "r", stdin);
19     #endif
20 
21     int N;
22     while(scanf("%d", &N) > 0) {
23         for(int i=0; i<N; ++i) scanf("%I64d", &a[i]);
24         int k = 0;
25         for(int i=0; i<N; ++i) {
26             for(int j=i+1; j<N; ++j) {
27                 b[k++] = a[i] + a[j];
28             }
29         }
30         sort(b, b+k);
31         int j = unique(b, b+k) - b;
32         long long S = 0;
33         for(int i=0; i<j; ++i) {
34             S += b[i];
35         }
36         printf("%I64d\n", S);
37     }
38     return 0;
39 }

 

Reading comprehension

 1 /*
 2 ID:esxgx1
 3 LANG:C++
 4 PROG:bestcoder8_B
 5 */
 6 #include <cstdio>
 7 #include <cstring>
 8 #include <iostream>
 9 #include <algorithm>
10 using namespace std;
11 
12 int M;
13 
14 const int n = 2;
15 struct mat {
16     int at[n][n];
17 };
18 
19 #define mod M
20 mat m22_m(const mat &a,const mat &b)
21 {
22     mat t;
23     for(int i=0;i<n;++i) {
24         for(int k=0;k<n;++k) {
25             long long u = 0;
26             for(int j=0;j<n;++j)
27                 u += (long long)a.at[i][j] * b.at[j][k];
28             t.at[i][k] = u % mod;
29         }
30     }
31     return t;
32 }
33 
34 mat expo(mat p,int k)
35 {
36     mat e;
37     memset(e.at,0,sizeof(e.at));
38     for(int i=0; i<n; ++i) e.at[i][i]=1;
39     for(;k; k>>=1) {
40         if(k & 1) e = m22_m(e, p);
41         p = m22_m(p,p);
42     }
43     return e;
44 }
45 
46 inline void DEC(int &a, int b){a -= b; if (a < 0) a += M;}
47 
48 int main(void)
49 {
50     #ifndef ONLINE_JUDGE
51     freopen("in.txt", "r", stdin);
52     #endif
53 
54     int N;
55     while(scanf("%d%d", &N, &M)>=0) {
56         mat p;
57         p.at[0][0] = 1, p.at[0][1] = 2;
58         p.at[1][0] = 1, p.at[1][1] = 0;
59         int rslt = expo(p, N).at[0][0];
60         if (!(N&1)) DEC(rslt, 1);
61         printf("%d\n", rslt);
62     }
63     return 0;
64 }

 

BestCoder Round #8

标签:style   blog   color   os   io   ar   for   div   sp   

原文地址:http://www.cnblogs.com/e0e1e/p/bestcoder_8.html

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