T1 factorial 100/100
The meaning of problems
T set of data, given N, to obtain N! Rightmost non-zero number.
For 30% of the data, N <= 30, T <= 10.
For all the data, N <= 10 ^ 2009, T <= 30.
A math problem
Resolve
N! / (10 ^ x) the last digit of that is the result. 10 ^ x split into 5 ^ x * 2 ^ x. How it is divided by 5 ^ x, easy to handle, take the time to contain an all multiples of 5 do not take into account, then a recursive process. which is
1 2 3 4 (15) 6 7 8 9 (25)
11 12 13 14 (35)16 17 18 19 (45)
21 22 23 24 (55) 26 27 28 29 (65) ...
Recursively processing
1 2 3 4 (1*5) 6
And can be found, is not a multiple of 5 in, a group of every ten, most end result is the same: 6 and 6 * 6 or 6!
The next question, how in addition to 2 ^ x it?
Analysis found:
2^0 = 1
2^1 = 2
2^2 = 4
2^3 = 8
2^4 =16=(6)
And 2,4,6,8 multiplied by 6 or the very end of the original number. So, you can look at x% 4 analyze how much, if it is 1, indicating that the original result multiplied by the equivalent of more than a 2 (the other 2 just those that are a multiple of four, does not affect the result), so we would have to be divided 2, but it is clear that the result multiplied by 3 to fix 2 (2 ^ 3) to eliminate the effect, get the right answer. Similarly other cases. At this point, thinking straightened out.
Code
#include<bits/stdc++.h>
using namespace std;
int T,n,ans,mod,rest,x;
bool flag;
const int v[10]={1,1,2,6,4,4,4,8,4,6};
char s[3000];
int a[3000];
const int k[4]={6,8,4,2};
int main(){
scanf("%d",&T);
while(T--){
scanf("%s",s);
memset(a,0,sizeof(a));
n=strlen(s);
for(int i=1;i<=n;++i){
a[i]=s[n-i]-'0';
}
ans=1;
mod=0;
flag=0;
while(1){
rest=0;
ans=(ans*v[a[1]])%10;
if(n>1) ans=(ans*6)%10;
for(int i=n;i>=1;i--){
x=rest*10+a[i];
rest=x%5;a[i]=x/5;
}
while((n>0)&&(a[n]==0)) n--;
if(n==0) break;
flag=true;
mod=(mod+a[2]*10+a[1])%4;
}
if(flag) ans=(ans*k[mod])%10;
printf("%d\n",ans);
}
return 0;
}
T2 turn 30/90
The meaning of problems
FIG n * n given, A is a starting point, B is the end point, to disorder *, can walk, bend ask a minimum of 90 degrees turn many times, can not reach the output of -1.
Resolve
Examination found that most make life difficult for the explosion, resulting in 90 points
Ideas: structure N * M * 4 points, each point is about the original image is split into four points. Wherein the point (i, j, k) represents the time (i, j) in the direction of the person is k, then for the two points (i, j, k) and (i, j, kk), if k and kk are two energy conversion directions of rotation of 90 degrees, and even a right edge of a side, and for (i, j, k) and (i + dx [k], j + dy [k], k) even a edge weight 0 to side, showing a case where the (i, j) in the direction of k can go to step k arrival direction (i + dx [k], j + dy [k], k). Since the direction of the start and end of uncertainty, so add a source and a sink point, the source point to the starting position for the right side connected four side directions of 0, sink connected to the terminating position of the four directions of the right side 0 side, and then find the shortest path to the source to the sink.
Burst Code Search
#include<bits/stdc++.h>
using namespace std;
int n,sx,sy,ex,ey,a[110][110];
char k;
bool book[110][110];
int ans=1<<30;
bool cheak(int x,int y){
if(x<1||y>n||y<1||x>n||a[x][y]||book[x][y]) return false;
else return true;
}
void dfs(int x,int y,int dir,int step){
if(x==ex&&y==ey){
ans=min(step,ans);
return;
}
if(step>ans) return;
if(dir){
if(cheak(x+1,y)){
book[x+1][y]=1;
dfs(x+1,y,dir,step);
book[x+1][y]=0;
}
if(cheak(x-1,y)){
book[x-1][y]=1;
dfs(x-1,y,dir,step);
book[x-1][y]=0;
}
if(cheak(x,y+1)){
book[x][y+1]=1;
dfs(x,y+1,0,step+1);
book[x][y+1]=0;
}
if(cheak(x,y-1)){
book[x][y-1]=1;
dfs(x,y-1,0,step+1);
book[x][y-1]=0;
}
}
else{
if(cheak(x+1,y)){
book[x+1][y]=1;
dfs(x+1,y,1,step+1);
book[x+1][y]=0;
}
if(cheak(x-1,y)){
book[x-1][y]=1;
dfs(x-1,y,1,step+1);
book[x-1][y]=0;
}
if(cheak(x,y+1)){
book[x][y+1]=1;
dfs(x,y+1,dir,step);
book[x][y+1]=0;
}
if(cheak(x,y-1)){
book[x][y-1]=1;
dfs(x,y-1,0,step);
book[x][y-1]=0;
}
}
}
int main(){
scanf("%d",&n);
for(int i=1;i<=n;++i){
for(int j=1;j<=n;++j){
scanf("%c",&k);
if(k=='A'){
sx=i;
sy=j;
}
else if(k=='B'){
ex=i;
ey=j;
}
else if(k=='x'){
a[i][j]=1;
}
else if(k=='.'){
a[i][j]=0;
}
else j--;
}
}
dfs(sx,sy,0,0);
dfs(sx,sy,1,0);
if(ans==1<<30) printf("-1");
else printf("%d",ans);
return 0;
}
T3 love running every day 20/20
The meaning of problems
Baidu own problems noip
Examination by a special point play, 20 points.
Code
The number of T4 fill game 100/95
The meaning of problems
Baidu own problems noip
Analysis: law questions, proof to later fill
Quick examination powers modulo a problem, overflow, so I lost 5 points
Code
#include<bits/stdc++.h>
using namespace std;
long long n,m;
long long ans;
long long f[10];
const long long mod=1e9+7;
long long power(int x,int y){
long long tmp=1;
while(y){
if(y&1) tmp=(x*tmp)%mod;
x=(x%mod*x%mod)%mod;
y>>=1;
}
return tmp;
}
int main(){
scanf("%lld %lld",&n,&m);
f[1]=2;
for(int i=2;i<=9;++i){
f[i]=f[i-1]*2;
}
if(n>m) swap(n,m);
if(n==1){
ans=power(2,m);
printf("%lld",ans%mod);
return 0;
}
else if(n==2) ans=12;
else if(n==3) ans=112;
else if(n==4) ans=912;
else{
ans=912;
for(int i=5;i<=n;++i){
ans=(ans*8-5*f[i])%mod;
}
}
if(m==n+1&&n>3) ans=ans*3-3*f[n];
else if(m==n+1) ans=ans*3;
if(m>n+1){
if(n>3) ans=ans*3-3*f[n];
else ans=ans*3;
for(int i=n+2;i<=m;++i){
ans=ans*3%mod;
}
}
printf("%lld",ans%mod);
return 0;
}