CSU-ACM2016暑假集训比赛1

                                                                                                                              A - Theatre Square

                                                                                     Time Limit:1000MS    Memory Limit:262144KB    64bit IO Format:%I64d & %I64u

Description

Input

Output

Sample Input

Sample Output

Hint

Description

Theatre Square in the capital city of Berland has a rectangular shape with the sizen × m meters. On the occasion of the city's anniversary, a decision was taken to pave the Square with square granite flagstones. Each flagstone is of the sizea × a.

What is the least number of flagstones needed to pave the Square? It's allowed to cover the surface larger than the Theatre Square, but the Square has to be covered. It's not allowed to break the flagstones. The sides of flagstones should be parallel to the sides of the Square.

Input

The input contains three positive integer numbers in the first line: n,  m anda (1 ≤  n, m, a ≤ 109).

Output

Write the needed number of flagstones.

Sample Input

Input
	6 6 4

Output
	4

题目大意:该城市的一块矩形广场需要铺设正方形的大理石地面,要求用完整的大理石铺设地面(允许铺设部分超出广场),而且广场地面必须铺满,大理石的边沿要与广场周边平行


本题比较简单,注意下数据类型的选取就行
#include<iostream>
using namespace std;
long long fun(long long y,long long x){
    if(y%x==0)
        return y/x;
    else
        return 1+y/x;
}
int main(){
    long long  n,m,a;
    while(cin>>n>>m>>a){
        cout<<fun(n,a)*fun(m,a)<<endl;
    }
    return 0;
}




                                                                                                                    B - Rightmost Digit
                                                                                     
                                                                                  Time Limit:1000MS    Memory Limit:32768KB    64bit IO Format:%I64d & %I64u

Description

Input

Output

Sample Input

Sample Output

Hint

Description

Given a positive integer N, you should output the most right digit of N^N.
 

Input

The input contains several test cases. The first line of the input is a single integer T which is the number of test cases. T test cases follow.
Each test case contains a single positive integer N(1<=N<=1,000,000,000).
 

Output

For each test case, you should output the rightmost digit of N^N.
 

Sample Input

           
           
2 3 4
 

Sample Output

           
           
7 6

Hint

 In the first case, 3 * 3 * 3 = 27, so the rightmost digit is 7. In the second case, 4 * 4 * 4 * 4 = 256, so the rightmost digit is 6. 

题目大意:给定一个整数N,求N^N结果最右边(末位)的数字

分析:本题考查数学归纳,由于任何数相乘结果的末位数只与相乘的数的末位数有关,而末位数最多情况为10种既0~9,因此只需从i^N(i从0到9)的每次运算的末位数即可得到所有数字的规律。

#include<iostream>
#include<math.h>
using namespace std;
int X[10][5];
int main(){
    int r,t,N;
    for(int i=0;i<10;i++)
        for(int j=1;j<=4;j++){
            r=(int)pow(i,j);
            X[i][j]=r%10;
        }
        for(int i=0;i<10;i++){
            X[i][0]=X[i][4];
        }
    cin>>t;
    while(t--){
        cin>>N;
        r=N%10;
        cout<<X[r][N%4]<<endl;
    }

    return 0;
}




                                                                                                                               D - Spreadsheets
                                                  
                                                                                    Time Limit:10000MS    Memory Limit:65536KB    64bit IO Format:%I64d & %I64u

Description

Input

Output

Sample Input

Sample Output

Hint

Description

  在一些知名的表格处理系统中(比如:excel表格),我们经常用大写的字母来表示列,例如A表示第1列,B表示第2列,第26列用Z来表示,同时第27列我们用AA来表示,第28列我们用AB来表示,第29列我们用AC来表示,AZ表示第52列,ZZ之后我们就需要用3个字母来表示列了。
  行的表示比较简单,我们一般用正整数来表示,比如1就表示第1行,5就表示第5行,行和列一起表示成为类似BC23的情况,这个表示在第23行,第55列。
  有时候,我们的系统也会用RXCY的格式来表示,X和Y是整数,分别表示行号和列号。例如:R23C55表示的位置和之前那个例子是一样的。
  你的任务是写一个程序,将这些位置在两种不同的表示方法之间转化。

Input

第一行是一个正整数n(1<=n<=10^5), 表示测试数据的数量。
接下来n行,每行一串字符,表示一个位置,输入保证所有的位置都是正确的,没有一个位置的行号或者列号超过10^ 6。

Output

输出n行,每行是对应的位置的转化结果。

Sample Input

2
R23C55
BC23

Sample Output

BC23
R23C55

分析:本题体现ASCII码的灵活运用、进制转换的代码能力。

#include<iostream>
#include<math.h>
#include<string>
using namespace std;
int get_ascii(char c){
    if(c>=65&&c<=90)
        return c-64;
    else if(c>=48&&c<=57){
        return c-48;
    }
}
char get_char(int n){
    if(n>0)
        return (char)(64+n);
    else
        return 'Z';
}

void to_r_c_r_c(string st){
    char str[20];
    int r=0,l=0,i;
    i=0;
    for(i=0;i<st.size();i++){
        str[i]=st[i];
    }
    i=0;
    for(;str[i]>=65;i++){
        r=r*26;
        r=r+get_ascii(str[i]);
    }
    for(;i<st.size();i++){
        l=l*10;
        l=l+get_ascii(str[i]);
    }
    cout<<"R"<<l<<"C"<<r<<endl;

}

void to_string(int n){
    int i=0,j=0;
    char c[5];
    for(;n>=1;i++){
        c[i]=get_char((n-1)%26+1);
        n=(n-1)/26;
    }
    for(j=i-1;j>=0;j--){
        cout<<c[j];
    }

}

void to_b_c(string st){
    char str[20];
    int r=0,l,i;
    for(i=0;i<st.size();i++){
        str[i]=st[i];
    }

    r=0;
    i=1;
    for(;str[i]<=57;i++){
        //cout<<"<";
        r=r*10;
        r=r+get_ascii(str[i]);
    }
    l=r;
    r=0;

    for(i=i+1;i<st.size();i++){
        r=r*10;
        r=r+get_ascii(str[i]);
    }
    to_string(r);
    cout<<l;
    cout<<endl;

}

int main(){
    int t;
    string s;
    cin>>t;
    while(t--){
        cin>>s;
        if((int)s[0]=='R'&&(int)s[1]<=57&&s.find('C')!=-1)
            to_b_c(s);
        else
            to_r_c_r_c(s);
    }

    return 0;
}



                                                                                                       E - Raising Modulo Numbers
                                                                      
                                                                                       Time Limit:1000MS    Memory Limit:30000KB    64bit IO Format:%lld & %llu

Description

Input

Output

Sample Input

Sample Output

Hint

Description

People are different. Some secretly read magazines full of interesting girls' pictures, others create an A-bomb in their cellar, others like using Windows, and some like difficult mathematical games. Latest marketing research shows, that this market segment was so far underestimated and that there is lack of such games. This kind of game was thus included into the KOKODáKH. The rules follow:

Each player chooses two numbers Ai and Bi and writes them on a slip of paper. Others cannot see the numbers. In a given moment all players show their numbers to the others. The goal is to determine the sum of all expressions Ai Bi from all players including oneself and determine the remainder after division by a given number M. The winner is the one who first determines the correct result. According to the players' experience it is possible to increase the difficulty by choosing higher numbers.

You should write a program that calculates the result and is able to find out who won the game.

Input

The input consists of Z assignments. The number of them is given by the single positive integer Z appearing on the first line of input. Then the assignements follow. Each assignement begins with line containing an integer M (1 <= M <= 45000). The sum will be divided by this number. Next line contains number of players H (1 <= H <= 45000). Next exactly H lines follow. On each line, there are exactly two numbers Ai and Bi separated by space. Both numbers cannot be equal zero at the same time.

Output

For each assingnement there is the only one line of output. On this line, there is a number, the result of expression

(A1B1+A2B2+ ... +AHBH)mod M.

Sample Input

3
16
4
2 3
3 4
4 5
5 6
36123
1
2374859 3029382
17
1
3 18132

Sample Output

2
13195
13

题目分析:本题考查快速幂求模,既可以根据二项式定理的展开并不断化解幂的次数,最终得到结果。

#include<iostream>
#include<math.h>
using namespace std;

#define N 45010
int AB[N][2];
int bin(int A,int B,int M){
    int n,a,c;
    a=A%M;
    c=1;
    n=B;
    if(A==0&&B!=0)
        return 0;
    else if(A!=0&&B==0)
        return 1;
    else if(A==1)
        return 1;
    for(;n>=1;){
        a=a%M;
        c=c%M;

        if(n%2==1){
            c=c*a;
            c=c%M;
            n=n/2;
            a=a*a;
            a=a%M;
        }
        else{
            c=c;
            c=c%M;
            n=n/2;
            a=a*a;
            a=a%M;
        }
    }

    return c;
}

int main(){
    int t,M,H,result;
    cin>>t;
    while(t--){
        result=0;
        cin>>M>>H;
        for(int i=0;i<H;i++){
            cin>>AB[i][0]>>AB[i][1];
            result=result+bin(AB[i][0],AB[i][1],M);

        }
        result=result%M;
        cout<<result<<endl;
    }


    return 0;
}


 
         
 
    
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值