20 solution to a problem off white cow month season (Bu Ti)

20 solution to a problem off white cow month season (Bu Ti)

Preface:
close to the edge of giving up. . . . .
Some board question actually was not going to do (Even if it will, but the board still only problem, they will not do a slight deformation, damage)
recent final exam again, I feel much better this semester subjects are good the water ah (Ran goose ACM level still do not see a great change), set up a flag: this winter brush mode of the 996 waiting for me! ! !


A, Feibolaqi (matrix quickly find the law & power)


This is my question people are stupid, Feibolaqi I actually do not know the law. . . .
After reading solution to a problem I knew
Alt
item 1, the first n items and the n = item * The first (n + 1)
a detailed explanation see this blog: https://blog.csdn.net/lanchunhui/article/details/51840616

2, when I think everything will be fine to know the law: write cycles of violence, and then continue to look Solution: My God, rapid power matrix, scared I'll put my matrix template used to power quickly,

Well, although have taken the template, but never done fast power matrix of questions (with do not know how to use)
so he read this blog:
https://blog.csdn.net/wust_zzwh/article/details/52058209 ###

The speakers also great, right, as the template still feel their own coding habits can be slightly modified

#include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
#include<queue>
#define mod(x) (x%MOD)
#define MOD 1000000007
#define ll long long 
using namespace std;
struct mat{
    ll m[2][2];
}unit;
//重载乘法运算符
mat operator * (mat a,mat &b){
    mat ret;
    memset(ret.m,0,sizeof(ret.m));
    for(int k=0;k<2;k++){
        for(int i=0;i<2;i++){
            if(a.m[i][k]){
                for(int j=0;j<2;j++){
                    ret.m[i][j]=mod(ret.m[i][j]+(ll)a.m[i][k]*b.m[k][j]);
                }
            }
        }
    }
    return ret;
}
//单位矩阵初始化
void init_unit(){
    for(int i=0;i<2;i++){
        unit.m[i][i]=1;
    }
    return ;
}
//矩阵快速幂
mat pow_mat(mat a,ll n){
    mat ret=unit;
    while(n){
        if(n&1){
            ret=ret*a;
        }
        n>>=1;
        a=a*a;
    }
    return ret;
}
int main(){
    init_unit();           //这个非常重要
    mat real;
    real.m[0][0]=1;
    real.m[0][1]=0;
    real.m[1][0]=1;
    real.m[1][1]=0;
    mat temp;
    temp.m[0][0]=1;
    temp.m[0][1]=1;
    temp.m[1][0]=1;
    temp.m[1][1]=0;
    ll n;
    cin>>n;
    if(n==1){
        cout<<1<<endl;
    }
    else{
        mat ans1=pow_mat(temp,n-2)*real;
        mat ans2=pow_mat(temp,n-1)*real;
        cout<<mod(ans1.m[0][0]*ans2.m[0][0])<<endl;
    }
    return 0;
}

I refer to the previous template a template: https://blog.csdn.net/f_zyj/article/details/52202169


B, the maximum side length


I have understanding the problem ah, mainly taking the maximum in both cases:
Here Insert Picture Description

Then there was the following code:

#include<cstdio>
#include<cstring>
#include<algorithm>
#include<iostream>
#include<queue>
#include<map>
#define ll long long
using namespace std;
int main(){
    ll a,b;
    cin>>a>>b;
    if(a<b){
        swap(a,b);
    }
    cout<<max(a/3,b/2);
    return 0;
}

When the game, you just can not find where the wrong, I am also a Buddha

The following is a standard process sub-sub:

#include<cstdio>
#include<cstring>
#include<algorithm>
#include<iostream>
#include<queue>
#include<map>
#define ll long long
using namespace std;
int main(){
    ll a,b;
    cin>>a>>b;
    if(a<b){
        swap(a,b);
    }
    cout<<max(min(a/3,b),b/2);
    return 0;
}

harm! ! ! !


E, a mere interval


Bare tree line, but still did not do it, that lazy feeling now is to mark stumbled. . .


F, hexadecimal conversion


Very silent, looking at Tarsus, Tarsus I was too lazy to put forward a template to knock it in C ++, began using Java
but failed to comprehend the essence of Java, many do not know encapsulation method used, resulting in a post on the wa, people are stupid
after reading the explanations found: Okay, Java nb!

import java.math.BigInteger;
import java.util.*;
public class Main{
	public static void main(String args[]) {
		Scanner scan=new Scanner(System.in);
		String str=scan.next();
		int a=scan.nextInt();
		int b=scan.nextInt();
		//a进制数转为b进制数
		String res=new BigInteger(str,a).toString(b);
		System.out.println(res);
	}
}

I, little pony


One can feel is dfs ah, but I do not know why the game when, dfs never before, leading to the collapse of my state of mind was, but just wrote a dfs code, a pay actually passed. . . .

#include<cstdio>
#include<cstring>
#include<algorithm>
#include<iostream>
#include<set>
#define INF 0x3f3f3f3f
#define ll long long
using namespace std;
int dirx[]={0,-1,-2,-2,-1,1,2,2,1};
int diry[]={0,-2,-1,1,2,2,1,-1,-2};
int mp[2010][2010];
int n,m;
int cnt;
void dfs(int x,int y){
    cnt++;
    mp[x][y]=1;
    for(int i=1;i<=8;i++){
        int fx=x+dirx[i];
        int fy=y+diry[i];
        if(fx>=1&&fx<=n&&fy>=1&&fy<=m&&mp[fx][fy]==0){
            dfs(fx,fy);
        }
    }
}
int main(){
    memset(mp,0,sizeof(mp));
    cin>>n>>m;
    cnt=0;
    dfs(1,1);
    if(cnt==n*m){
        cout<<"Yes"<<endl;
    }
    else{
        cout<<"No"<<endl;
    }
}

Looked at the solution to a problem, actually was thinking of an exam question, see specific codes:

#include<cstdio>
#include<cstring>
#include<algorithm>
#include<iostream>
#include<set>
#define INF 0x3f3f3f3f
#define ll long long
using namespace std;
int main(){
    int n,m;
    cin>>n>>m;
    if((n>=3&&m>=3&&(n+m!=6))||(n==1&&m==1)){
        cout<<"Yes"<<endl;
    }
    else{
        cout<<"No"<<endl;
    }
    return 0;
}

J, dh hat


Standard solution to a problem. . .
Here Insert Picture Description


K、Hello World


Buddha also, this attendance problem. . .

#include<cstdio>
#include<cstring>
#include<algorithm>
#include<iostream>
#include<set>
#include<queue>
#include<map>
#define ll long long
using namespace std;
ll a[1010];
int main(){
    int n,m,k,x;
    cin>>n>>m>>k;
    for(int i=1;i<+n;i++){
        cin>>x;
    }
    cout<<"I Love nowcoder"<<endl;
    return 0;
}

Feel I learned a matrix fast power , the Java for large numbers of Sao operation , lazy tree line marks continue recycled , J Kankan tomorrow's digital dp

Published 127 original articles · won praise 32 · views 10000 +

Guess you like

Origin blog.csdn.net/boliu147258/article/details/103653326