23暑假友谊赛No.2

23暑假友谊赛No.2

#include<bits/stdc++.h>
using namespace std;
#define int long long
//#define int __int128
typedef pair<int,int>PII;

typedef pair<string,int>PSI;
typedef pair<string,string>PSS;
const int N=50+5,INF=0x3f3f3f3f,Mod=1e9+7,mod=998244353;
const int inf=0x3f3f3f3f3f3f;
const double eps=1e-6;
const int dx[4]={-1,0,1,0};
const int dy[4]={0,1,0,-1};


void solve(){

    vector<int>ve(4);
    for(int i=0;i<4;++i)cin>>ve[i];
    int x;cin>>x;
    for(int i=0;i<4;++i){
        if(ve[i]<x)cout<<x-ve[i]<<' ';
        else cout<<0<<' ';
    }
}
signed main(){
    ios::sync_with_stdio(0),cin.tie(0),cout.tie(0);
    int T=1;
    //init();
    //cin>>T;
    while(T--){
        solve();
    }
    return 0;
}
View Code

 

思路:整理下式子发现答案是n*n

#include<bits/stdc++.h>
using namespace std;
#define int long long
//#define int __int128
typedef pair<int,int>PII;

typedef pair<string,int>PSI;
typedef pair<string,string>PSS;
const int N=50+5,INF=0x3f3f3f3f,Mod=1e9+7,mod=998244353;
const int inf=0x3f3f3f3f3f3f;
const double eps=1e-6;
const int dx[4]={-1,0,1,0};
const int dy[4]={0,1,0,-1};


void solve(){

    int n;cin>>n;
    cout<<(n%mod)*(n%mod)%mod;
}
signed main(){
    ios::sync_with_stdio(0),cin.tie(0),cout.tie(0);
    int T=1;
    //init();
    //cin>>T;
    while(T--){
        solve();
    }
    return 0;
}
View Code

 

思路:结构体比较

#include<bits/stdc++.h>
using namespace std;
#define int long long
//#define int __int128
typedef pair<int,int>PII;

typedef pair<string,int>PSI;
typedef pair<string,string>PSS;
const int N=50+5,INF=0x3f3f3f3f,Mod=1e9+7,mod=998244353;
const int inf=0x3f3f3f3f3f3f;
const double eps=1e-6;
const int dx[4]={-1,0,1,0};
const int dy[4]={0,1,0,-1};

struct E{
    string a;
    double k;
    bool operator<(const E&e)const{
        if(k!=e.k)return k>e.k;
        return a<e.a;
    }
};
void solve(){
    string s;cin>>s;
    int n;cin>>n;
    vector<string>ve(n);
    vector<E>ans;
    for(int i=0;i<n;++i){
        cin>>ve[i];
        if(ve[i].size()==s.size()){
            int m=0;
            for(int j=0;j<s.size();++j){
                m+=(ve[i][j]==s[j]);
            }
            double kk=m*1.0/s.size();
            ans.push_back({ve[i],kk});
        }
    }
    if(ans.size()==0){
        sort(ve.begin(),ve.end());
        for(int i=0;i<ve.size();++i)cout<<ve[i]<<'\n';
    }else{
        sort(ans.begin(),ans.end());
        for(int i=0;i<ans.size();++i){
            if(ans[i].k==ans[0].k){
                cout<<ans[i].a<<'\n';
            }else break;
        }
    }
}
signed main(){
    ios::sync_with_stdio(0),cin.tie(0),cout.tie(0);
    int T=1;
    //init();
    //cin>>T;
    while(T--){
        solve();
    }
    return 0;
}
View Code

 

思路:每个数取最大或最小带来的贡献是最大的;

dp[i][j]表示前i个数的情况且第i个数在j(j=0,j=1)位置的最大值,j=0表示a[i]取1,j=1表示a[i]取b[i];

#include<bits/stdc++.h>
using namespace std;
#define int long long
//#define int __int128
typedef pair<int,int>PII;

typedef pair<string,int>PSI;
typedef pair<string,string>PSS;
const int N=1e5+5,INF=0x3f3f3f3f,Mod=1e9+7,mod=998244353;
const int inf=0x3f3f3f3f3f3f;
const double eps=1e-6;
const int dx[4]={-1,0,1,0};
const int dy[4]={0,1,0,-1};
int dp[N][2];
void solve(){
    int n;cin>>n;
    vector<int>ve(n);
    for(int i=0;i<n;++i)cin>>ve[i];
    for(int i=1;i<n;++i){
        dp[i][0]=max(dp[i-1][0],dp[i-1][1]+abs(ve[i-1]-1));
        dp[i][1]=max(dp[i-1][0]+abs(ve[i]-1),dp[i-1][1]+abs(ve[i-1]-ve[i]));
    }
    cout<<max(dp[n-1][0],dp[n-1][1]);
}
signed main(){
    ios::sync_with_stdio(0),cin.tie(0),cout.tie(0);
    int T=1;
    //init();
    //cin>>T;
    while(T--){
        solve();
    }
    return 0;
}
View Code

 

思路:倒着取654321,哪个缺补哪里

#include<bits/stdc++.h>
using namespace std;
#define int long long
//#define int __int128
typedef pair<int,int>PII;

typedef pair<string,int>PSI;
typedef pair<string,string>PSS;
const int N=1e5+5,INF=0x3f3f3f3f,Mod=1e9+7,mod=998244353;
const int inf=0x3f3f3f3f3f3f;
const double eps=1e-6;
const int dx[4]={-1,0,1,0};
const int dy[4]={0,1,0,-1};

void solve(){
    int s;cin>>s;
    vector<int>k(7);
    for(int i=1;i<=6;++i)cin>>k[i];
    int now=k[6]+k[5]+k[4]+(k[3]+3)/4;
    k[1]=max(0ll,k[1]-11*k[5]);
    int c=k[4]*5;
    int d=min(k[2],c);
    k[2]-=d,c-=d;
    if(c)k[1]=max(0ll,k[1]-c*4);
    c=4-k[3]%4;
    if(c!=4){
        d=2*c-1;
        int c1=min(k[2],d);
        k[2]-=c1;
        int d1=c*9-c1*4;
        k[1]=max(0ll,k[1]-d1);
    }
    if(k[2]>0){
        c=(k[2]+8)/9;
        now+=c;
        d=9-k[2]%9;
        if(d!=9)k[1]=max(0ll,k[1]-d*4);
    }
    if(k[1]>0){
        c=(k[1]+35)/36;
        now+=c;
    }
    if(now>s)cout<<"No\n";
    else cout<<"Yes\n";
}
signed main(){
    ios::sync_with_stdio(0),cin.tie(0),cout.tie(0);
    int T=1;
    //init();
    cin>>T;
    while(T--){
        solve();
    }
    return 0;
}
View Code

 

 思路:将每个人的路径转换为二进制,f[i][j]表示前i个人的状态,且第i个人的路径为j的数量,且第i个人的状态只和前i-1个人有关,维护一维就可以,时间复杂为n*2m,会超。

由题目给出的数据条件,可以枚举√2m,即把二进制的16位分为两部分,高位的8位为x,低位的8位为y,f[i][j][k]表示前i个人的状态,且第i个人的路径的高位为j,低位&k为0的数量。

那么枚举每个人的高位,而后更新低位的状态

 
#include<bits/stdc++.h>
using namespace std;
#define int long long
//#define int __int128
typedef pair<int,int>PII;

typedef pair<string,int>PSI;
typedef pair<string,string>PSS;
const int N=256+5,INF=0x3f3f3f3f,Mod=1e9+7,mod=998244353;
const int inf=0x3f3f3f3f3f3f;
const double eps=1e-6;
const int dx[4]={-1,0,1,0};
const int dy[4]={0,1,0,-1};

int dp[N][N];
void solve(){
    int n,m,ans=0;cin>>n>>m;
    for(int i=0;i<n;++i){
        string s;cin>>s;
        int x=0,y=0;
        for(int j=0;j<s.size();++j){
            x=x*2+(s[j]=='o');
        }
        y=x%256,x=x/256;
        int now=1;
        for(int j=0;j<256;++j){
            if(x&j)continue;
            now=(now+dp[j][y])%mod;
        }
        ans=(ans+now)%mod;
        for(int j=0;j<256;++j){
            if(y&j)continue;
            dp[x][j]=(dp[x][j]+now)%mod;
        }
    }
    cout<<ans;
}
signed main(){
    ios::sync_with_stdio(0),cin.tie(0),cout.tie(0);
    int T=1;
    //init();
    //cin>>T;
    while(T--){
        solve();
    }
    return 0;
}
View Code

 

posted @ 2023-07-26 19:34  bible_w  阅读(4)  评论(0编辑  收藏  举报