• CodeChef November Challenge 2013 解题报告


    Uncle Johny

    题目链接:http://www.codechef.com/NOV13/problems/JOHNY

    水题。排序即可

    代码如下:

     1 #include <iostream>
     2 #include <cstdio>
     3 #include <cstring>
     4 #include <algorithm>
     5 using namespace std;
     6 
     7 typedef struct{
     8     int pos, val;
     9 }aa;
    10 
    11 aa a[1010];
    12 
    13 bool cmp(aa x,aa y)
    14 {
    15     return x.val<y.val;
    16 }
    17 
    18 int main()
    19 {
    20 //    freopen("in.txt", "r", stdin);
    21 
    22     int T, n, k;
    23     scanf("%d", &T);
    24     for(int cnt = 1; cnt<=T; cnt++)
    25     {
    26         scanf("%d", &n);
    27         for(int i=1; i<=n; i++)
    28         {
    29             a[i].pos = i;
    30             scanf("%d", &a[i].val);
    31         }
    32         scanf("%d", &k);
    33         sort(a+1, a+n+1, cmp);
    34         for(int i=1; i<=n; i++){
    35             if(a[i].pos == k){
    36                 printf("%d
    ", i);
    37                 break;
    38             }
    39         }
    40 
    41     }
    42     return 0;
    43 }
    View Code

    Missing some chairs

    题目链接:http://www.codechef.com/NOV13/problems/MCHAIRS

    计算2^n - 1。快速模幂

    代码如下:

     1 #include <iostream>
     2 #include <cstdio>
     3 #include <cstring>
     4 #define MOD 1000000000+7
     5 using namespace std;
     6 
     7 long long a_b_MOD_c(long long a, long long b, long long c)
     8 {
     9     if(b==1)
    10         return a%c;
    11     long long temp = a_b_MOD_c(a, b/2, c);
    12     if(b%2 == 1)
    13         return (temp*temp*a)%c;
    14     else
    15         return (temp*temp)%c;
    16 }
    17 
    18 int main()
    19 {
    20 //    freopen("in.txt", "r", stdin);
    21 
    22     int T;
    23     long long n;
    24     scanf("%d", &T);
    25     while(T--){
    26         scanf("%lld", &n);
    27         printf("%lld
    ", a_b_MOD_c(2,n,MOD)-1);
    28     }
    29     return 0;
    30 }
    View Code

    Square Digit Squares

    题目链接:http://www.codechef.com/NOV13/problems/SDSQUARE

    找到1-1e10之间的平方数并且只含有0.1.4.9

    暴力枚举平方数,打表即可

    代码如下:

     1 #include <iostream>
     2 #include <cstdio>
     3 #include <cstring>
     4 #include <cmath>
     5 #include <algorithm>
     6 #define ll long long
     7 using namespace std;
     8 
     9 int tag[600000], sum[600000];
    10 
    11 bool Judge(ll n)
    12 {
    13     while(n){
    14         if(n%10==0 || n%10==1 || n%10==4 || n%10==9);
    15         else return false;
    16         n/=10;
    17     }
    18     return true;
    19 }
    20 
    21 int main()
    22 {
    23 //    freopen("in.txt", "r" , stdin);
    24 
    25     int T;
    26     ll a, b;
    27     memset(tag, 0, sizeof tag);
    28     memset(sum, 0, sizeof sum);
    29     for(ll i=1; i<100100; i++){
    30         if(Judge(i*i)){
    31             tag[i] = 1;
    32         }
    33         sum[i] = sum[i-1]+tag[i];
    34     }
    35     scanf("%d", &T);
    36     while(T--)
    37     {
    38         scanf("%lld%lld", &a, &b);
    39         int temp = (sqrt(a)-(int)sqrt(a))==0?1:0;
    40         int ans = sum[(int)sqrt(b)] - sum[(int)sqrt(a)-temp];
    41         printf("%d
    ", ans);
    42     }
    43     return 0;
    44 }
    View Code

    Superpowers of 2

    题目链接:http://www.codechef.com/NOV13/problems/SPOTWO

    也是快速模幂,数据卡的比较死一定要用unsigned long long才行,最后平方一定要分开做

    代码如下:

     1 #include <iostream>
     2 #include <cstdio>
     3 #include <cstring>
     4 #include <algorithm>
     5 #define ll unsigned long long
     6 #define MOD 1000000000+7
     7 using namespace std;
     8 
     9 ll a_b_MOD_c(ll a, ll b, ll c)
    10 {
    11     ll product = a,ans = 1;
    12     while(b)
    13     {
    14         if(b&1==1){
    15             ans *= product;
    16             ans %= c;
    17         }
    18         b>>=1;
    19         product = (product*product)%c;
    20     }
    21     return ans;
    22 }
    23 
    24 ll Change(ll n)
    25 {
    26     int dig[1000], top = 0;
    27     while(n){
    28         dig[top++] = (n&1)?1:0;
    29         n>>=1;
    30     }
    31     ll ret = 0;
    32     for(int i=top-1; i>=0; i--){
    33         ret += dig[i]==1?1:0;
    34         if(i!=0)ret*=10;
    35     }
    36     return ret;
    37 }
    38 
    39 int main()
    40 {
    41 //    freopen("in.txt", "r" , stdin);
    42 
    43     int T;
    44     ll n;
    45     scanf("%d", &T);
    46     while(T--)
    47     {
    48         scanf("%llu", &n);
    49         ll ans = a_b_MOD_c(2, Change(n), MOD);
    50         ans = a_b_MOD_c(ans, 2, MOD);
    51         printf("%llu
    ", ans);
    52     }
    53     return 0;
    54 }
    View Code
    奔跑吧!少年!趁着你还年轻
  • 相关阅读:
    包装器
    高级new创建
    野性的呼唤 第三章
    SourceTree的基本使用
    SAP的春天回来么?
    dirname命令和basename命令
    一个简单的ETL脚本的内容
    轮子:读取config.ini文件
    sed基础语法
    hivesql之str_to_map函数
  • 原文地址:https://www.cnblogs.com/shu-xiaohao/p/3403052.html
Copyright © 2020-2023  润新知