周赛解题报告

A hard puzzle

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 39205    Accepted Submission(s): 14062



Problem Description
lcy gives a hard puzzle to feng5166,lwg,JGShining and Ignatius: gave a and b,how to know the a^b.everybody objects to this BT problem,so lcy makes the problem easier than begin.
this puzzle describes that: gave a and b,how to know the a^b's the last digit number.But everybody is too lazy to slove this problem,so they remit to you who is wise.
 

Input
There are mutiple test cases. Each test cases consists of two numbers a and b(0<a,b<=2^30)
 

Output
For each test case, you should output the a^b's last digit number.
 

Sample Input
  
  
7 66 8 800
 

Sample Output
  
  
9 6
 

Author
eddy
 

Recommend
JGShining

找出a的b次方的最后一位数是多少,这道题有两种方法可以做,最简单的就是找到其中的规律,可以发现1~9每个数的次方幂的最后一位的变化周期都为4,例如7^1=7,7^2=9,7^3=3,7^4=1;8^1=8,8^2=4,8^3=2,8^4=6;因为只求最后一位数,所以底数只需要计算个位数,指数只需要计算模4后的值。

#include <iostream>
#include<cstdio>
#include<cstring>
using namespace std;


int main()
{
    long long int n,m;                               
    int f[35];
    memset(f,0,sizeof(f));
    while(scanf("%lld%lld",&n,&m)!=EOF)
    {
        int a=n%10,b=m%4,ans=1;
        if(b==0) b=4;
        for(int i=0;i<b;i++)
        {
            ans=ans*a;
            ans%=10;                                      
        }
        printf("%d\n",ans);
    }
    return 0;
}



另一个方法就是把指数二分,求快速幂

#include <cstdio>
#include <cstring>
typedef __int64 LL;
const int mod = 10;
LL solve(LL a,LL b)
{
    LL res = 1;
    LL temp = a%mod;
    for(;b;b=b/2)
    {
        if(b%2==1)
            res=(res*temp)%mod;                                     
        temp = (temp*temp)%mod;                                   
    }
    return res;
}
int main()
{
    LL a,b;
    while(scanf("%I64d%I64d",&a,&b)!=EOF)
    {
        printf("%I64d\n",solve(a,b));
    }
    return 0;
}




A + B Again

Time Limit: 1000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 22402    Accepted Submission(s): 9694


Problem Description
There must be many A + B problems in our HDOJ , now a new one is coming.
Give you two hexadecimal integers , your task is to calculate the sum of them,and print it in hexadecimal too.
Easy ? AC it !
 

Input
The input contains several test cases, please process to the end of the file.
Each case consists of two hexadecimal integers A and B in a line seperated by a blank.
The length of A and B is less than 15.
 

Output
For each test case,print the sum of A and B in hexadecimal in one line.
 

Sample Input
  
  
+A -A +1A 12 1A -9 -1A -12 1A -AA
 

Sample Output
  
  
0 2C 11 -2C -90
 

Author
linle
 

Source
 

Recommend
linle

这道题需要注意的是都为long long,然后输入输出直接写%llx则为16进制的long long,当答案为负数的时候要先输出负号,再输出绝对值(至于为什么用%llx输入可以有负号输出却不能输出负号,我也不清楚)

#include <iostream>
#include<cstdio>
using namespace std;


int main()
{
    long long int a,b,c;
    while(scanf("%llX%llX",&a,&b)!=EOF)
    {
        c=a+b;
        if(c<0){
            c=c*(-1);
            printf("-");
        }
        printf("%llX\n",c);
    }
    return 0;
}




Physical Examination

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 7356    Accepted Submission(s): 2210


Problem Description
WANGPENG is a freshman. He is requested to have a physical examination when entering the university.
Now WANGPENG arrives at the hospital. Er….. There are so many students, and the number is increasing!
There are many examination subjects to do, and there is a queue for every subject. The queues are getting longer as time goes by. Choosing the queue to stand is always a problem. Please help WANGPENG to determine an exam sequence, so that he can finish all the physical examination subjects as early as possible.
 

Input
There are several test cases. Each test case starts with a positive integer n in a line, meaning the number of subjects(queues).
Then n lines follow. The i-th line has a pair of integers (ai, bi) to describe the i-th queue:
1. If WANGPENG follows this queue at time 0, WANGPENG has to wait for ai seconds to finish this subject.
2. As the queue is getting longer, the waiting time will increase bi seconds every second while WANGPENG is not in the queue.
The input ends with n = 0.
For all test cases, 0<n≤100000, 0≤a i,b i<2 31.
 

Output
For each test case, output one line with an integer: the earliest time (counted by seconds) that WANGPENG can finish all exam subjects. Since WANGPENG is always confused by years, just print the seconds mod 365×24×60×60.
 

Sample Input
  
  
5 1 2 2 3 3 4 4 5 5 6 0
 

Sample Output
  
  
1419
Hint
In the Sample Input, WANGPENG just follow the given order. He spends 1 second in the first queue, 5 seconds in the 2th queue, 27 seconds in the 3th queue, 169 seconds in the 4th queue, and 1217 seconds in the 5th queue. So the total time is 1419s. WANGPENG has computed all possible orders in his 120-core-parallel head, and decided that this is the optimal choice.
 

Source
 

Recommend
zhuyuanchen520   |   We have carefully selected several similar problems for you:   5717  5716  5715  5714  5713 

最重要的问题就是那个排序,假如两个点a(x,y),b(x,y),计算所需的时间为T1(先做a后做b)=a.x+b.x+a.x*b.y,T2(先做b后做a)=a.x+b.x+b.x*a.y;a.x+b.x+a.x*b.y<a.x+b.x+b.x*a.y;约后得a.x*b.y<b.x*a.y;

#include <iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
struct subject
{
    long long int a,b;
}s[100100];
bool cmp(subject s1,subject s2)
{
    return s1.a*s2.b<s2.a*s1.b;                                       //排序
}
int main()
{
    int n;
    while(scanf("%d",&n))
    {
        if(n==0)
            break;
        for(int i=0;i<n;i++)
        {
            scanf("%lld%lld",&s[i].a,&s[i].b);
        }
        sort(s,s+n,cmp);
        long long int ans=0,all=0;
        for(int i=0;i<n;i++)
        {
            ans=s[i].a+all*s[i].b;
            all=all+ans;
            all%=365*24*60*60;                                       
        }
        printf("%lld\n",all);
    }
    return 0;
}


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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值