week3

SMU Winter 2023 Round #5 (Div.2)

Lucky?

int main(){
    int t,a[6];
    cin>>t;
    while(t--){
    scanf("%1d%1d%1d%1d%1d%1d",&a[0],&a[1],&a[2],&a[3],&a[4],&a[5]);
    if(a[0]+a[1]+a[2]==a[3]+a[4]+a[5])cout<<"YES\n";
    else cout<<"NO\n";
    }
    return 0;
}
 

Equal Candies

 思路:找出最小的数
int main(){
    int t,n,a[55];
    cin>>t;
    while(t--){
        int mi=N;
        cin>>n;
        for(int i=0;i<n;++i){
            cin>>a[i];
            if(a[i]<mi)mi=a[i];
        }
        long long s=0;
        for(int i=0;i<n;++i){
            s+=(a[i]-mi);
        }
        cout<<s<<'\n';
    }
    return 0;
}

 

Most Similar Words

 思路:枚举每一对
#include<bits/stdc++.h>
using namespace std;
const int N=1e7+10;
int main(){
    int t,n,m;
    string a[55];
    cin>>t;
    while(t--){
        cin>>n>>m;
        for(int i=0;i<n;++i)cin>>a[i];
        int mi=N;
        for(int i=0;i<n-1;++i)
            for(int j=i+1;j<n;++j){
                int s=0;
                for(int k=0;k<m;++k){
                    s+=(a[i][k]+a[j][k]-2*min(a[i][k],a[j][k]));
                }
                mi=min(mi,s);
            }
        cout<<mi<<'\n';
    }
    return 0;
}

 

X-Sum

思路:枚举每个点的对角线和
#include<bits/stdc++.h>
using namespace std;
const int N=1e7+10;
int main(){
    int t,n,m;
    int a[205][205];
    int dx[4]={-1,-1,1,1},dy[4]={-1,1,-1,1};
    cin>>t;
    while(t--){
        cin>>n>>m;
        int res=0;
        for(int i=1;i<=n;++i)
            for(int j=1;j<=m;++j)
                cin>>a[i][j];
        for(int i=1;i<=n;++i)
            for(int j=1;j<=m;++j){
                int s=0;
                s+=a[i][j];
                for(int k=1;k<=max(n,m);++k){
                    for(int u=0;u<4;++u){
                        int xx=k*dx[u]+i,yy=k*dy[u]+j;
                        if(xx>0&&xx<=n&&yy>0&&yy<=m)
                            s+=a[xx][yy];
                    }
                }
                res=max(res,s);
            }
        cout<<res<<'\n';
    }
    return 0;
}

 

Eating Queries

 思路:对所有数降序排序后求前缀和,前缀和为升序,二分查找x
#include<bits/stdc++.h>
using namespace std;
const int N=150005;
typedef long long ll;
bool cmp(int a,int b){
    return a>b;
}
int main(){
    int t,n,q,a[N];
    ll x;
    cin>>t;
    while(t--){
        cin>>n>>q;
        for(int i=0;i<n;++i)cin>>a[i];
        sort(a,a+n,cmp);
        for(int i=1;i<n;++i)a[i]+=a[i-1];
        while(q--){
            cin>>x;
            if(x>a[n-1])cout<<-1<<'\n';
            else if(x==a[n-1])cout<<n<<'\n';
            else{
                ll s=lower_bound(a,a+n,x)-a;
                if(s<n)cout<<s+1<<'\n';
                else cout<<-1<<'\n';
            }
        }
    }
    return 0;
}

 

Longest Strike

 思路:用map存储每个数个数,刚好得到排列后的序列,查找个数都大于等于k的连续区间
#include<bits/stdc++.h>
using namespace std;
const int N=1e6+10;
typedef long long ll;
int t,n,k,l,r,maxl,mi,ma,len,last,a[N];
map<int,int>mp;
int main(){
    cin>>t;
    while(t--){
        cin>>n>>k;
        mp.clear(),maxl=0,mi=0x3f3f3f3f,ma=0,len=0;
        for(int i=1;i<=n;++i){
            cin>>a[i];
            mp[a[i]]++;
            mi=min(mi,a[i]),ma=max(ma,a[i]);
        }
        last=mi-1;
        for(auto v:mp){
            int i=v.first;
            if(i==ma&&v.second>=k&&i==last+1&&len+1>maxl)maxl=len+1,l=i-len,r=i;
            if(v.second>=k&&i==last+1)len++;
            else{
                if(len>maxl)maxl=len,l=last+1-len,r=last;
                if(v.second>=k)len=1;
                else len=0;
            }
            last=i;
        }

    if(maxl!=0)cout<<l<<' '<<r<<'\n';
    else if(mp[ma]>=k)cout<<ma<<' '<<ma<<'\n';
    else cout<<"-1\n";
}
    return 0;
}

 

 White-Black Balanced Subtrees

思路:dfs求子树的点的黑白个数是否相同

#include<bits/stdc++.h>
using namespace std;
const int N=4010;
vector<int>ve[N];
int f[N][2];
string s;
void dfs(int u,int fa)
{
    if(s[u]=='W') f[u][0]++;
    else f[u][1]++;
    for(int i=0;i<ve[u].size();i++)
    {
        int j=ve[u][i];
        if(j==fa) continue;
        dfs(j,u);
        f[u][0]+=f[j][0],f[u][1]+=f[j][1];
    }
}
int main(void)
{
    int t; cin>>t;
    while(t--)
    {
        int n; cin>>n;
        for(int i=1;i<=n;i++) ve[i].clear(),f[i][0]=0,f[i][1]=0;
        for(int i=2;i<=n;i++)
        {
            int x; cin>>x;
            ve[x].push_back(i),ve[i].push_back(x);
        }
        cin>>s;
        s="0"+s;
        dfs(1,-1);
        int cnt=0;
        for(int i=1;i<=n;i++) if(f[i][0]==f[i][1]) cnt++;
        cout<<cnt<<'\n';
    }
    return 0;
}

 

 
 思路:求i<j,a[i]>=a[j]的个数,easy:双指针,hard:树状数组或归并排序
#include<bits/stdc++.h>
using namespace std;
const int N=1e5*2+10;
typedef long long ll;
int t,n,a[N],tr[N];
int lowbit(int x){
    return x&-x;
}
void update(int x,ll v){
    for(int i=x;i<N;i+=lowbit(i))tr[i]+=v;
}
ll q(int x){
    ll sum=0;
    for(int i=x;i;i-=lowbit(i))sum+=tr[i];
    return sum;
}
int main(){
    cin>>t;
    while(t--){
        cin>>n;
        for(int i=0;i<=n+10;++i)tr[i]=0;
        for(int i=1;i<=n;++i)cin>>a[i];
        ll ans=0;
        for(int i=1;i<=n;++i){
            ans+=q(n+1)-q(a[i]-1);
            update(a[i],1);
        }
        cout<<ans<<'\n';
    }
    return 0;
}

 

 SMU Winter 2023 Round #6 (Div.2)

OP

#include<bits/stdc++.h>
using namespace std;
int main(){
    cout<<"fengqibisheng, yingyueerlai!";
    return 0;
}

Steel of Heart

思路:模拟每一种技能
#include<bits/stdc++.h>
using namespace std;
int main(){
    int h1,h2;
    int m;
    cin>>h1>>h2>>m;
    char x;
    bool ok=false;
    int mm,ss,a,b,t[2][5]={{0,0,0,0,0},{0,0,0,0,0}};
    while(m--){
        cin>>mm>>x>>ss>>a;
        if(a==1){
            h1+=800;
            ok=true;

        }
        else if(a==2){
            h1+=h2;
        }
        else{
            cin>>b;
            if(ok){
                if(mm==t[0][b-1]&&ss>=t[1][b-1]||mm>t[0][b-1]){
                    h1+=double((125.0+0.06*h1))*0.1;
                    t[1][b-1]=(ss+30)%60;
                    if((ss+30)>=60)t[0][b-1]=mm+1;
                    else t[0][b-1]=mm;
                }
            }
        }
    }
    cout<<h1;
    return 0;
}

 

思路:排序后,若a[j]-a[i]=9 (i<j),则少一种可能
#include<bits/stdc++.h>
using namespace std;
int main(){
    const int N=500005;
    int n;
    cin>>n;
    vector<int>a(n);
    int s=n;
    for(int i=0;i<n;++i){
        cin>>a[i];
    }
    sort(a.begin(),a.end());
    for(int i=0;i<n;++i)
        for(int j=i+1;j<n;++j){
            if(a[j]-a[i]==9)s--;
            if(a[j]-a[i]>9)break;
        }
    cout<<s;
    return 0;
}

 

 

Survivor

思路:计算出每个人存活需要的次数,排序后从小到大取
#include<bits/stdc++.h>
using namespace std;
const int N=2e5+5;
int a[N],b[N],c[N],s[N];
int main(){
    int n,k,m;
    cin>>n>>m>>k;
    for(int i=0;i<n;++i){
        scanf("%d",a+i);
    }
    for(int i=0;i<n;++i){
        scanf("%d",b+i);
    }
    for(int i=0;i<n;++i){
        scanf("%d",c+i);
    }
    for(int i=0;i<n;++i){
        long long all=a[i]-m*b[i];
        if(all<=0){
            int t=1;
            while(all+t*c[i]<=0)t++;
            s[i]=t;
        }
    }
    int cnt=0;
    sort(s,s+n);
    for(int i=0;i<n;++i){
        cnt+=s[i];
        if(cnt>k){
            cout<<i;
            break;
        }
    }
    return 0;
}

 

 

Simple Game

思路:判断总和的奇偶性

#include <bits/stdc++.h>
using namespace std;

int main(){
    long long n,k;
    long long s=0;
    cin>>n;
    for(int i=1;i<=n;i++){
        scanf("%lld",&k);
        s+=k;
    }
    if(s%2)printf("Alice");
    else printf("Bob");
    return 0;
}

 

Bit

思路:记录n次操作分别对二进制第i位为0或1后的结果,对于每次询问,二进制从最高位到低位枚举,第i位当初始为0,结果为1或0的情况答案都为0;当初始为1,结果为1,且该情况的数不超过r,答案为1,其他都为0

#include<bits/stdc++.h>
using namespace std;
const int N=2e5+5;
int n,q,a,b,x=0,y,xx[30],yy[30];
int main(){
    cin>>n>>q;
    for(int i=0;i<30;++i)y|=(1<<i);
    for(int i=0;i<n;++i){
        cin>>a>>b;
        if(a==1)x=x&b,y=y&b;
        else if(a==2)x=x|b,y=y|b;
        else x=x^b,y=y^b;
    }
    for(int i=29;i>=0;--i){
        xx[i]=(x>>i)&1;
        yy[i]=(y>>i)&1;
    }
    int s;
    while(q--){
        s=0;
        cin>>a;
        for(int i=29;i>=0;--i){
            if(xx[i]!=1&&yy[i]==1){
                if((s+(1<<i))<=a)s|=(1<<i);
            }
        }
        cout<<s<<'\n';
    }
    return 0;
}

 

Elden Ring

思路:对2n个数编号,若编号是m的倍数,该编号与编号%n交换
#include<bits/stdc++.h>
using namespace std;
int main(){
    int n,m,k;
    cin>>n>>m>>k;
    int a[2005];
    for(int i=1;i<=2*n;++i)a[i]=i;
    for(int i=1;i<=k;++i){
        int j=i%n;
        if(j==0)j=n;
        if(i%m==0)swap(a[j],a[j+n]);
    }
    for(int i=1;i<=2*n;++i)cout<<a[i]<<' ';
    return 0;
}

 

SMU Winter 2023 Round #7 (Div.2)

思路:统计每个字符数量,统计偶数对个数,若出现奇数,总数加一,若没有奇数,总数减一
#include<bits/stdc++.h>
using namespace std;
const int N=2e5+5;
int main(){
    int t,n;
    cin>>t;
    char a;
    while(t--){
        int b[60]={0},s=0;
        cin>>n;
        for(int i=0;i<n;++i){
            cin>>a;
            b[a-'A']++;
        }
        bool ok=false;
        for(int i=0;i<58;++i){
            if(b[i]%2==1)ok=true;
            if(b[i]!=0)
            s+=((b[i]/2)*2);
        }
        if(ok)s++;
        cout<<s<<'\n';
    }
    return 0;
}

 

 

7 的意志

思路:用前缀和统计区间和为7777的个数
#include<bits/stdc++.h>
using namespace std;
const int N=1e5+5;
int n,t,a[N];
int main(){
    cin>>t;
    while(t--){
        scanf("%d",&n);
        a[0]=0;
        for(int i=1;i<=n;++i)scanf("%d",&a[i]);
        int cnt=0;
        for(int i=1;i<=n;++i)a[i]+=a[i-1];
        for(int i=1;i<=n;++i){
            int s=a[i-1]+7777;
            int p= lower_bound(a+1,a+n+1,s)-a;
            if(a[p]==s)cnt++;
        }
        printf("%d\n",cnt);
    }
    return 0;
}

 

思路:更新每一次操作后的物体的坐标,自己的位置,拿到的物体数 
#include<bits/stdc++.h>
using namespace std;
const int N=1e5+5;
int n,x[2005][2005],y[2005][2005],q,s[2005];
int px[2005],py[2005],ans[2005],a[2005],b[2005],op[2005],vis[2005][2005];
int main(){
    cin>>n;
    for(int i=1;i<=n;++i){
        cin>>x[0][i]>>y[0][i];
        vis[0][i]=0;
    }
    cin>>q;
    for(int i=1;i<=q;++i){
        cin>>op[i];
        if(op[i]==1){
            string ss;
            cin>>ss;
            if(ss[0]=='X')a[i]=1;
            else a[i]=2;
            cin>>b[i];
        }
        else if(op[i]==2){
            string ss;
            cin>>ss;
            if(ss[0]=='X')a[i]=1;
            else a[i]=2;
        }
        else if(op[i]==4)cin>>a[i];
    }
    px[0]=py[0]=ans[0]=0;
    for(int i=1;i<=q;++i){
        ans[i]=ans[i-1];
        px[i]=px[i-1];
        py[i]=py[i-1];
        if(op[i]==4){
            memcpy(x[i],x[a[i]-1],sizeof(x[i]));
            memcpy(y[i],y[a[i]-1],sizeof(y[i]));
            memcpy(vis[i],vis[a[i]-1],sizeof(vis[i]));
            ans[i]=ans[a[i]-1];
            px[i]=px[a[i]-1];
            py[i]=py[a[i]-1];
            continue;
        }
        memcpy(x[i],x[i-1],sizeof (x[i]));
        memcpy(y[i],y[i-1],sizeof(y[i]));
        memcpy(vis[i],vis[i-1],sizeof(vis[i]));
        if(op[i]==1){
            if(a[i]==1){
                int l=min(px[i],px[i]+b[i]);
                int r=max(px[i],px[i]+b[i]);
                px[i]+=b[i];
                if(px[i]!=0&&py[i]!=0){
                    px[i]=py[i]=0;
                    continue;
                }
                for(int j=1;j<=n;++j){
                    if(!vis[i][j]&&y[i][j]==0&&l<=x[i][j]&&x[i][j]<=r){
                        vis[i][j]=1;++ans[i];
                    }
                }
            }
            else{
                int l=min(py[i],py[i]+b[i]);
                int r=max(py[i],py[i]+b[i]);
                py[i]+=b[i];
                if(px[i]!=0&&py[i]!=0){
                    px[i]=py[i]=0;
                    continue;
                }
                for(int j=1;j<=n;++j){
                    if(!vis[i][j]&&x[i][j]==0&&l<=y[i][j]&&y[i][j]<=r){
                        vis[i][j]=1;++ans[i];
                    }
                }
            }
        }
        else if(op[i]==2){
            if(a[i]==1){
                for(int j=1;j<=n;++j)x[i][j]*=(-1);
            }
            else
                for(int j=0;j<=n;++j)y[i][j]*=(-1);
        }
        else if(op[i]==3){
            for(int j=1;j<=n;++j)swap(x[i][j],y[i][j]);
        }
        for(int j=1;j<=n;++j)
            if(!vis[i][j]&&px[i]==x[i][j]&&py[i]==y[i][j]){
                ++ans[i];vis[i][j]=1;
                break;
            }
    }
    cout<<ans[q];
    return 0;
}

 

转动命运之轮

思路:答案为快乐值总和与操作数的乘积,模拟n = 1 , 2 , ⋯   , 5 ,发现系数p 的值分别等于1 , 3 , 12 , 60 , 360 
#include<bits/stdc++.h>
using namespace std;
const int N=998244353;
typedef long long ll;
ll n,sum=0,tmp=1;
ll a[2005];
int main(){
    cin>>n;
    for(int i=1;i<=n;++i){
        cin>>a[i];
        sum=(sum+a[i])%N;
    }
    for(int i=2;i<=n;++i)
        tmp=(tmp*(i+1))%N;
    cout<<(sum*tmp)%N;
    return 0;
}

 

 
 

计算最小值

思路:对选取数的操作后使得和最小,就是让选取数中最大值减去最小值的值最小。选取数量为n,将所有数排列,从最小的开始,用双指针算法,当选取的数刚好为n时记录最小的res
#include<bits/stdc++.h>
using namespace std;
typedef pair<int,int>PII;
const int N=998244353;
typedef long long ll;
int n,m;
int read(){
    int x = 0 , ch = getchar();
    while( ch < '0' || ch > '9' ) ch = getchar();
    while( ch >= '0' && ch <= '9' ) x = ( x << 3 ) + ( x << 1 ) + ch - '0' , ch = getchar();
    return x;
}
vector<PII>v;
int main(){
    n=read(),m=read();
    vector<int>cnt(n+1);
    for (int i = 1; i <= n; ++i) {
        for (int j = 1,x; j <= m; ++j) {
            x=read();v.push_back({x,i});
        }
    }
    sort(v.begin(),v.end());
    int res=1e9;
    for(int l=0,r=-1;l<v.size();++l){
        while(r+1<v.size()&&cnt[0]!=n){
            r++,cnt[v[r].second]++;
            if(cnt[v[r].second]==1)cnt[0]++;
        }
        if(cnt[0]!=n)break;
        if(v[l].second!=v[r].second)res=min(res,v[r].first-v[l].first);
        cnt[v[l].second]--;
        if(cnt[v[l].second]==0)cnt[0]--;
    }
    cout<<res<<'\n';
    return 0;
}

 

 

 

月光奏鸣曲

思路:将正方形一与旋转1次和2次的正方形二作比较
#include<bits/stdc++.h>
using namespace std;
const int N=1e5+5;
int t,n,a[25][25],b[25][25];
int main(){
    cin>>t;
    while(t--){
        cin>>n;
        for(int i=0;i<n;++i)
            for(int j=0;j<n;++j)cin>>a[i][j];
        for(int i=0;i<n;++i)
            for(int j=0;j<n;++j)cin>>b[i][j];
        bool ok=true;
        int ans=0;
        for(int i=0;i<n&&ok;++i)
            for(int j=0;j<n;++j)
                if(a[i][j]!=b[i][j]){
                    ok=false;
                    break;
                }
        if(!ok){
            ok=true;ans=1;
            for(int i=0;i<n&&ok;++i)
                for(int j=0;j<n;++j)
                    if(a[i][j]!=b[j][n-i-1]){
                    ok=false;
                    break;
                }
        }
        if(!ok){
            ok=true;ans=2;
            for(int i=0;i<n&&ok;++i)
                for(int j=0;j<n;++j)if(a[i][j]!=b[n-i-1][n-j-1]){
                    ok=false;
                    break;
                }
        }
        if(!ok){
            ok=true;ans=1;
            for(int i=0;i<n&&ok;++i)
                for(int j=0;j<n&&ok;++j)if(a[i][j]!=b[n-j-1][i]){
                    ok=false;
                    break;
                }
        }
        if(ok)cout<<ans<<'\n';
        else cout<<-1<<'\n';
    }
    return 0;
}

 

 

电子表校对

 思路:将一个数字分段为三段,区分0~9
#include<bits/stdc++.h>
using namespace std;
const int N=1e5+5;
int main(){
    string a[5],b[5];
    for(int i=0;i<3;++i){
        getline(cin,a[i]);
    }
    for(int i=0;i<3;++i)getline(cin,b[i]);
    int c[6],d[6];
    for(int i=0;i<6;++i){
        string x[5];
        for(int j=0;j<3;++j){
            x[j]=a[j].substr(i*3,3);
        }
        if(x[0]=="   "&&x[1]=="  |"&&x[2]=="  |")c[i]=1;
        else if(x[0]==" _ "&&x[1]==" _|"&&x[2]=="|_ ")c[i]=2;
        else if(x[0]==" _ "&&x[1]==" _|"&&x[2]==" _|")c[i]=3;
        else if(x[0]=="   "&&x[1]=="|_|"&&x[2]=="  |")c[i]=4;
        else if(x[0]==" _ "&&x[1]=="|_ "&&x[2]==" _|")c[i]=5;
        else if(x[0]==" _ "&&x[1]=="|_ "&&x[2]=="|_|")c[i]=6;
        else if(x[0]==" _ "&&x[1]=="  |"&&x[2]=="  |")c[i]=7;
        else if(x[0]==" _ "&&x[1]=="|_|"&&x[2]=="|_|")c[i]=8;
        else if(x[0]==" _ "&&x[1]=="|_|"&&x[2]==" _|")c[i]=9;
        else c[i]=0;
        for(int j=0;j<3;++j)x[j]=b[j].substr(i*3,3);
        if(x[0]=="   "&&x[1]=="  |"&&x[2]=="  |")d[i]=1;
        else if(x[0]==" _ "&&x[1]==" _|"&&x[2]=="|_ ")d[i]=2;
        else if(x[0]==" _ "&&x[1]==" _|"&&x[2]==" _|")d[i]=3;
        else if(x[0]=="   "&&x[1]=="|_|"&&x[2]=="  |")d[i]=4;
        else if(x[0]==" _ "&&x[1]=="|_ "&&x[2]==" _|")d[i]=5;
        else if(x[0]==" _ "&&x[1]=="|_ "&&x[2]=="|_|")d[i]=6;
        else if(x[0]==" _ "&&x[1]=="  |"&&x[2]=="  |")d[i]=7;
        else if(x[0]==" _ "&&x[1]=="|_|"&&x[2]=="|_|")d[i]=8;
        else if(x[0]==" _ "&&x[1]=="|_|"&&x[2]==" _|")d[i]=9;
        else d[i]=0;
    }
    int h[2],m[2],s[2],hh,mm,ss;
    h[0]=c[0]*10+c[1],h[1]=d[0]*10+d[1];
    m[0]=c[2]*10+c[3],m[1]=d[2]*10+d[3];
    s[0]=c[4]*10+c[5],s[1]=d[4]*10+d[5];
    if(h[0]==h[1]&&m[0]==m[1]&&s[0]==s[1]){
        cout<<"gang gang hao\n";
        hh=mm=ss=0;
    }
    else if((h[0]==h[1]&&((m[0]==m[1]&&s[0]>s[1])||(m[0]>m[1])))||h[0]>h[1]){
        cout<<"early\n";
        if(s[0]>=s[1])ss=s[0]-s[1];
        else{
            ss=60+s[0]-s[1];m[0]--;
        }
        if(m[0]>=m[1])mm=m[0]-m[1];
        else{
            mm=60+m[0]-m[1];h[0]--;
        }
        hh=h[0]-h[1];
    }
    else {
        cout<<"late\n";
        if(s[1]>=s[0])ss=s[1]-s[0];
        else{ss=60+s[1]-s[0];m[1]--;}
        if(m[1]>=m[0])mm=m[1]-m[0];
        else{mm=60+m[1]-m[0];h[1]--;}
        hh=h[1]-h[0];
    }
    c[0]=hh/10,c[1]=hh%10,c[2]=mm/10,c[3]=mm%10,c[4]=ss/10,c[5]=ss%10;
    for(int i=0;i<3;++i){
        for(int j=0;j<6;++j){
            if(i==0){
                if(c[j]==4||c[j]==1)cout<<"   ";
                else cout<<" _ ";
            }
            else if(i==1){
                if(c[j]==1||c[j]==7)cout<<"  |";
                else if(c[j]==2||c[j]==3)cout<<" _|";
                else if(c[j]==5||c[j]==6)cout<<"|_ ";
                else if(c[j]==8||c[j]==9||c[j]==4)cout<<"|_|";
                else cout<<"| |";
            }
            else{
                if(c[j]==1||c[j]==4||c[j]==7)cout<<"  |";
                else if(c[j]==2)cout<<"|_ ";
                else if(c[j]==3||c[j]==5||c[j]==9)cout<<" _|";
                else cout<<"|_|";
            }
        }cout<<'\n';
    }
    return 0;
}

 

第二版本:

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

const int N=20+5,M=998244353;
string a[3],b[3];
string ans[3][10]={{" _ ","   "," _ "," _ ","   "," _ "," _ "," _ "," _ "," _ "},
        {"| |","  |"," _|"," _|","|_|","|_ ","|_ ","  |","|_|","|_|"},
                   {"|_|","  |","|_ "," _|","  |"," _|","|_|","  |","|_|"," _|"}
};

string P(int x,string s[]){
    string y1=s[0].substr(x,3),y2=s[1].substr(x,3),y3=s[2].substr(x,3);
    if(y1==" _ "&&y2=="| |"&&y3=="|_|")return "0";
    if(y1=="   "&&y2=="  |"&&y3=="  |")return "1";
    if(y1==" _ "&&y2==" _|"&&y3=="|_ ")return "2";
    if(y1==" _ "&&y2==" _|"&&y3==" _|")return "3";
    if(y1=="   "&&y2=="|_|"&&y3=="  |")return "4";
    if(y1==" _ "&&y2=="|_ "&&y3==" _|")return "5";
    if(y1==" _ "&&y2=="|_ "&&y3=="|_|")return "6";
    if(y1==" _ "&&y2=="  |"&&y3=="  |")return "7";
    if(y1==" _ "&&y2=="|_|"&&y3=="|_|")return "8";
    if(y1==" _ "&&y2=="|_|"&&y3==" _|")return "9";
}
int main(){
    cin.tie(0),cout.tie(0);
    for(int i=0;i<3;++i)
        getline(cin,a[i]);
    for(int i=0;i<3;++i)
        getline(cin,b[i]);
    string c,d;
    for(int i=0;i+3<=18;i+=3){
        c+=P(i,a);
        d+=P(i,b);
    }
    int a1,b1,c1,a2,b2,c2,t1,t2,t3;
    a1=(c[0]-'0')*10+c[1]-'0',b1=(c[2]-'0')*10+c[3]-'0',c1=(c[4]-'0')*10+c[5]-'0';
    a2=(d[0]-'0')*10+d[1]-'0',b2=(d[2]-'0')*10+d[3]-'0',c2=(d[4]-'0')*10+d[5]-'0';
    int q=0;
    if(a1==a2){
        if(b1==b2){
            if(c1==c2)cout<<"gang gang hao\n";
            else if(c1>c2)cout<<"early\n",q=1;
            else cout<<"late\n",q=2;
        }
        else if(b1>b2)cout<<"early\n",q=1;
        else cout<<"late\n",q=2;
    }
    else if(a1>a2)cout<<"early\n",q=1;
    else cout<<"late\n",q=2;
    if(q==1){
        t3=c1-c2;
        if(t3<0){
            t3+=60;
            b1--;
        }
        t2=b1-b2;
        if(t2<0){
            t2+=60;
            a1--;
        }
        t1=a1-a2;
    }
    else if(q==2){
        t3=c2-c1;
        if(t3<0){
            t3+=60;
            b2--;
        }
        t2=b2-b1;
        if(t2<0){
            t2+=60;
            a2--;
        }
        t1=a2-a1;
    }
    else t1=t2=t3=0;
    for(int i=0;i<3;++i){
        cout<<ans[i][t1/10]<<ans[i][t1%10];
        cout<<ans[i][t2/10]<<ans[i][t2%10];
        cout<<ans[i][t3/10]<<ans[i][t3%10];
        cout<<'\n';
    }
    return 0;
}
View Code 2

 

简单的 LRU 问题

思路:模拟
#include<bits/stdc++.h>
using namespace std;
const int N=998244353;
typedef long long ll;
int n,m,mx;
int a[105][10];
string hx = "0123456789abcdef";
int main(){
    cin >> n >> m;
    mx = 0;
    cout << "+------+";
    for (int i = 0; i < n; ++i) {
        cout << "--------+";
    }
    cout << '\n';
    cout << "|      |";
    for (int i = 0; i < n; ++i) {
        cout << "  0x";
        int a = i / 16, b = i % 16;
        cout << hx.substr(a, 1) << hx.substr(b, 1) << "  |";
    }
    cout << '\n';
    cout << "+------+";
    for (int i = 0; i < n; ++i) {
        cout << "--------+";
    }
    cout << '\n';
    for (int i = 0; i < m; ++i) {
        int x; cin >> x;
        if (i == 0) a[0][0] = x;
        else {
            int have = 0;
            for (int j = 0; j <= mx; ++j) {
                if (a[i - 1][j] == x) {
                    have = 1; break;
                }
            }
            if (have) {
                int k = 0;
                for (int j = 0; j <= mx; ++j) {
                    if (a[i - 1][j] == x) continue;
                    a[i][k++] = a[i - 1][j];
                }
                a[i][mx] = x;
            }
            else {
                if (mx < n - 1) {
                    for (int j = 0; j <= mx; ++j) {
                        a[i][j] = a[i - 1][j];
                    }
                    a[i][++mx] = x;
                }
                else {
                    int k = 0;
                    for (int j = 1; j <= mx; ++j) {
                        a[i][k++] = a[i - 1][j];
                    }
                    a[i][mx] = x;
                }
            }
        }
        cout << "| 0x";
        int A, B, C, D; A = i / 16; B = i % 16;
        cout << hx.substr(A, 1) << hx.substr(B, 1) << " |";
        for (int j = 0; j <= mx; ++j) {
            cout << " 0x";
            int tmp = a[i][j];
            A = tmp / 4096; tmp -= A * 4096;
            B = tmp / 256; tmp -= B * 256;
            C = tmp / 16; tmp -= C * 16;
            D = tmp;
            cout << hx.substr(A, 1) << hx.substr(B, 1);
            cout << hx.substr(C, 1) << hx.substr(D, 1) << " |";
        }
        for (int j = mx + 1; j < n; ++j) {
            cout << "        |";
        }
        cout << '\n';
        cout << "+------+";
        for (int i = 0; i < n; ++i) {
            cout << "--------+";
        }
        cout << '\n';
    }
    return 0;
}

 

思路:排列喜爱度后输出k+1个
#include<bits/stdc++.h>
using namespace std;
const int N=1e5+5;
typedef pair<int,string> P;
vector<P>ve;
bool cmp(P a,P b){
    return a.first>b.first;
}
int main(){
    int n,k;
    cin>>n;
    int x;
    string a;
    for(int i=0;i<n;++i){
        cin>>x>>a;
        ve.push_back({x,a});
    }
    sort(ve.begin(),ve.end(),cmp);
    cin>>k;
    cout<<ve[k].second;
    return 0;
}

 

 

毁灭凤凰人

思路:统计拥有卡牌,根据表示形式比较是否能将毁灭凤凰人送入墓地和除外
#include<bits/stdc++.h>
using namespace std;
const int N=1e5+5;
int n,m;
int main(){
    cin>>n>>m;
    int x,y,yy=0,a=0,b=0;
    for(int i=1;i<=n;++i){
        cin>>x;
        if(x==0){
            cin>>y;yy=max(yy,y);
        }
        else if(x==1)a=1;
        else b=1;
    }
    if(a&&m==0&&yy>=2500)cout<<"haoye";
    else if(a&&m==1&&yy>2100)cout<<"haoye";
    else if(b&&n>1)cout<<"haoye";
    else cout<<"QAQ";
    return 0;
}

 

#include<bits/stdc++.h>
using namespace std;
const int N=2e5+5;
int main(){
    int n;
    cin>>n;
    for(int i=0;i<n;++i)cout<<"Welcome to HZNU\n";
    return 0;
}

 

 

Ayanoto 变形记

思路:只有x为0时跳不到
#include<bits/stdc++.h>
using namespace std;
const int N=1e5+5;
int main(){
    int t,n,x;
    cin>>t;
    while(t--){
        cin>>n>>x;
        if(x==0)cout<<"no"<<'\n';
        else{
            cout<<"yes"<<'\n';
        }
    }
    return 0;
}

 

 

P 龙学长的教诲

 思路:区分出符号,前后依次输出
#include<bits/stdc++.h>
using namespace std;
const int N=1e5+5;
int t;
string a[1005];
int main(){
    cin>>t;
    while(t--){
        int n;
        string x;
        for(int i=0;;++i){
            cin>>a[i];
            char b=a[i][a[i].size()-1];
            if(b=='.'||b=='!'||b=='?'){
                x=b;n=i+1;a[i]=a[i].substr(0,a[i].size()-1);
                break;
            }
        }
        int z=0,y=n-1;
        for(int i=1;i<=n;++i){
            if(i%2)cout<<a[z++];
            else cout<<a[y--];
            if(i<n)cout<<' ';
        }cout<<x<<'\n';
    }
    return 0;
}

 

 
 
posted @ 2023-01-17 01:24  bible_w  阅读(23)  评论(0编辑  收藏  举报