Bestcoder round #8

Source: Internet
Author: User

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_JUDGE18     freopen("in.txt", "r", stdin);19     #endif20 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 M20 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_JUDGE51     freopen("in.txt", "r", stdin);52     #endif53 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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.