zoukankan      html  css  js  c++  java
  • 湖南工业大学创新实验室2015年新生赛(一)1002(重开)

    工大第一美男子的回归故事

    Time Limit : 3000/1000ms (Java/Other)   Memory Limit : 65535/32768K (Java/Other)
    Total Submission(s) : 39   Accepted Submission(s) : 23

    Font: Times New Roman | Verdana | Georgia

    Font Size: ← →

    Problem Description

    工大第一美男子月神从阿里回来了,ACM的小伙伴们自然是十分的开心!
    当然,他们这么开心除了是想月神之外,也是想狠狠宰月神一顿。
    月神毕竟是月神,财大气粗,除了请客之外,他还会解答小伙伴们的疑问。

    但是,问题一来,就如同排山倒海,让月神应接不暇,所以,他想让你帮帮忙,代他回答这些问题。

    对于每个整数q,代表问题,整数p,代表啪啪啪你要输出的是 a = q^p。

    Input

    多组输入,每组输入两个整数q和p(1<=q<=10,1<=p<=9)

    Output

    对于每一组数据首先输入一个case #: #代表第几组数据
    然后输出一个整数a,代表结果

    Sample Input

    1 1
    2 2
    3 3

    Sample Output

    case 1:1
    case 2:4
    case 3:27

    Author

    ikids
     
    没什么好说的,就是a = q^p罢了,实在怕超时可以用快速幂
    #include<stdio.h>
    //#include<bits/stdc++.h>
    #include<string.h>
    #include<iostream>
    #include<math.h>
    #include<sstream>
    #include<set>
    #include<queue>
    #include<vector>
    #include<algorithm>
    #include<limits.h>
    #define inf 0x3fffffff
    #define lson l,m,rt<<1
    #define rson m+1,r,rt<<1|1
    #define LL long long
    using namespace std;
    int pow(int x, int n)
    {
        int pw = 1;
        while (n > 0)
        {
            if (n & 1)        // n & 1 等价于 (n % 2) == 1
                pw *= x;
            x *= x;
            n >>= 1;        // n >>= 1 等价于 n /= 2
        }
        return pw;
    }
    int main()
    {
        int p,q;
        int num=1;
        while(cin>>p>>q)
        {
            printf("case %d:%d
    ",num++,pow(p,q));
        }
        return 0;
    }
    

      

  • 相关阅读:
    CF 149D Coloring Brackets(区间DP,好题,给配对的括号上色,求上色方案数,限制条件多,dp四维)
    hdu 4607 树形dp 树的直径
    poj 2955 区间dp入门题
    poj 2139 flord水题
    poj 2377 最大生成树
    lightoj 1422 区间dp
    模拟类似括号匹配
    nyoj 33 蛇形填数
    nyoj 2 括号配对问题水
    Hackonacci Matrix Rotations 观察题 ,更新了我的模板
  • 原文地址:https://www.cnblogs.com/yinghualuowu/p/4995000.html
Copyright © 2011-2022 走看看