A hard puzzle
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)Total Submission(s): 40440 Accepted Submission(s): 14591
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.
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
#include <iostream>
#include <cstring>
#include <cstdio>
#include <algorithm>
#include <vector>
#include <cmath>
#include <queue>
#include <map>
#include <set>
using namespace std;
const int maxn = 100;
int c[maxn];
int n;
int lowbit(int x){
return x&(-x);
}
void update(int x,int val){
while(x<=maxn){
c[x] += val;
x += lowbit(x);
}
}
int getsum(int x){
int sum=0;
while(x>0){
sum += c[x];
x -=lowbit(x);
}
return sum;
}
int save[maxn];
void change(int position,int val){
int i;
for(i=position;i>1;i--){
save[i] = save[i-1];
}
save[1] = val;
}
bool judge(){
int i;
for(i=1;i<n;i++){
if(save[i]>save[i+1]){
return false;
}
}
return true;
}
int main(){
long long a,b;
while(~scanf("%lld%lld",&a,&b)){
long long hu = a%10;
if(hu==1){
printf("1\n");
continue;
}else if(hu==2){
long long res2[4] = {6,2,4,8};
printf("%lld\n",res2[b%4]);
continue;
}else if(hu==3){
long long res3[4] = {1,3,9,7};
printf("%lld\n",res3[b%4]);
continue;
}else if(hu==4){
long long res4[2] = {6,4};
printf("%lld\n",res4[b%2]);
continue;
}else if(hu==5){
printf("5\n");
continue;
}else if(hu==6){
printf("6\n");
continue;
}else if(hu==7){
long long res7[4]={1,7,9,3};
printf("%lld\n",res7[b%4]);
}else if(hu==8){
long long res8[4]={6,8,4,2};
printf("%lld\n",res8[b%4]);
}else if(hu==9){
long long res9[2]={1,9};
printf("%lld\n",res9[b%2]);
}else {
printf("0\n");
}
}
return 0;
}
Reorder the Books
Time Limit: 4000/2000 MS (Java/Others) Memory Limit: 131072/131072 K (Java/Others)Total Submission(s): 1312 Accepted Submission(s): 703
Problem Description
dxy has a collection of a series of books called "The Stories of SDOI",There are
n(n≤19)
books in this series.Every book has a number from
1
to
n
.
dxy puts these books in a book stack with the order of their numbers increasing from top to bottom. dxy takes great care of these books and no one is allowed to touch them.
One day Evensgn visited dxy's home, because dxy was dating with his girlfriend, dxy let Evensgn stay at home himself. Evensgn was curious about this series of books.So he took a look at them. He found out there was a story about "Little E&Little Q". While losing himself in the story,he disrupted the order of the books.
Knowing that dxy would be back soon,Evensgn needed to get the books ordered again.But because the books were too heavy.The only thing Evensgn could do was to take out a book from the book stack and and put it at the stack top.
Give you the order of the disordered books.Could you calculate the minimum steps Evensgn would use to reorder the books? If you could solve the problem for him,he will give you a signed book "The Stories of SDOI 9: The Story of Little E" as a gift.
dxy puts these books in a book stack with the order of their numbers increasing from top to bottom. dxy takes great care of these books and no one is allowed to touch them.
One day Evensgn visited dxy's home, because dxy was dating with his girlfriend, dxy let Evensgn stay at home himself. Evensgn was curious about this series of books.So he took a look at them. He found out there was a story about "Little E&Little Q". While losing himself in the story,he disrupted the order of the books.
Knowing that dxy would be back soon,Evensgn needed to get the books ordered again.But because the books were too heavy.The only thing Evensgn could do was to take out a book from the book stack and and put it at the stack top.
Give you the order of the disordered books.Could you calculate the minimum steps Evensgn would use to reorder the books? If you could solve the problem for him,he will give you a signed book "The Stories of SDOI 9: The Story of Little E" as a gift.
Input
There are several testcases.
There is an positive integer T(T≤30) in the first line standing for the number of testcases.
For each testcase, there is an positive integer n in the first line standing for the number of books in this series.
Followed n positive integers separated by space standing for the order of the disordered books,the ith integer stands for the ith book's number(from top to bottom).
Hint:
For the first testcase:Moving in the order of book3,book2,book1 , (4,1,2,3)→(3,4,1,2)→(2,3,4,1)→(1,2,3,4) ,and this is the best way to reorder the books.
For the second testcase:It's already ordered so there is no operation needed.
There is an positive integer T(T≤30) in the first line standing for the number of testcases.
For each testcase, there is an positive integer n in the first line standing for the number of books in this series.
Followed n positive integers separated by space standing for the order of the disordered books,the ith integer stands for the ith book's number(from top to bottom).
Hint:
For the first testcase:Moving in the order of book3,book2,book1 , (4,1,2,3)→(3,4,1,2)→(2,3,4,1)→(1,2,3,4) ,and this is the best way to reorder the books.
For the second testcase:It's already ordered so there is no operation needed.
Output
For each testcase,output one line for an integer standing for the minimum steps Evensgn would use to reorder the books.
Sample Input
2 4 4 1 2 3 5 1 2 3 4 5
Sample Output
3 0
Source
#include <iostream>
#include <cstring>
#include <cstdio>
#include <algorithm>
#include <vector>
#include <cmath>
#include <queue>
#include <map>
#include <set>
using namespace std;
const int maxn = 100;
int c[maxn];
int n;
int lowbit(int x){
return x&(-x);
}
void update(int x,int val){
while(x<=maxn){
c[x] += val;
x += lowbit(x);
}
}
int getsum(int x){
int sum=0;
while(x>0){
sum += c[x];
x -=lowbit(x);
}
return sum;
}
int save[maxn];
void change(int position,int val){
int i;
for(i=position;i>1;i--){
save[i] = save[i-1];
}
save[1] = val;
}
bool judge(){
int i;
for(i=1;i<n;i++){
if(save[i]>save[i+1]){
return false;
}
}
return true;
}
int main(){
int t,n,i,j;
int ans;
scanf("%d",&t);
while(t--){
scanf("%d",&n);
for(i=1;i<=n;i++){
scanf("%d",&save[i]);
}
ans=n;
int killme=n;
for(j=n;j>=1;j--){
for(i=1;i<=killme;i++){
if(save[i]==ans){
killme=i;
ans--;
break;
}
}
}
printf("%d\n",ans);
}
return 0;
}