5.21考试总结

考试总结

被快速幂坑了,有一个小地方忘取模了,咕咕咕

预计分数:100+100+100=300

实际分数:100+30+100=230

P1328 生活大爆炸版石头剪刀布

链接

#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cmath>
#include<queue>
#include<stack>
#include<vector>
#include<map>
#include<string>
#include<cstring>
using namespace std;
inline int read() {
    char c = getchar();
    int x = 0, f = 1;
    while(c < '0' || c > '9') {
        if(c == '-') f = -1;
        c = getchar();
    }
    while(c >= '0' && c <= '9') x = x * 10 + c - '0', c = getchar();
    return x * f;
}
/*0 表示"剪刀",1 表示"石头",2 表示"布",3 表示"蜥蜴人",4表示"斯波克"*/
int n,na,nb,x,y,xa[2205],xb[2205],i,j,ans,bns;
signed main() {
    freopen("rps.in","r",stdin);
    freopen("rps.out","w",stdout);
    cin>>n>>na>>nb;
    for(i=1; i<=na; i++) {
        xa[i]=read();
    }
    for(j=1; j<=nb; j++) {
        xb[j]=read();
    }
    ans=0;
    bns=0;
    i=0;
    j=0;
    for(int rps=1; rps<=n; rps++) {
        i++;
        j++;
        if(i>na)    
            i=1;
        if(j>nb)    
            j=1;
        if(xa[i]==0 && xb[j]==1)    bns++;
        if(xa[i]==0 && xb[j]==2)    ans++;
        if(xa[i]==0 && xb[j]==3)    ans++;
        if(xa[i]==0 && xb[j]==4)    bns++;
        if(xa[i]==1 && xb[j]==0)    ans++;
        if(xa[i]==1 && xb[j]==2)    bns++;
        if(xa[i]==1 && xb[j]==3)    ans++;
        if(xa[i]==1 && xb[j]==4)    bns++;
        if(xa[i]==2 && xb[j]==0)    bns++;
        if(xa[i]==2 && xb[j]==1)    ans++;
        if(xa[i]==2 && xb[j]==3)    bns++;
        if(xa[i]==2 && xb[j]==4)    ans++;
        if(xa[i]==3 && xb[j]==0)    bns++;
        if(xa[i]==3 && xb[j]==1)    bns++;
        if(xa[i]==3 && xb[j]==2)    ans++;
        if(xa[i]==3 && xb[j]==4)    ans++;
        if(xa[i]==4 && xb[j]==0)    ans++;
        if(xa[i]==4 && xb[j]==1)    ans++;
        if(xa[i]==4 && xb[j]==2)    bns++;
        if(xa[i]==4 && xb[j]==3)    bns++;
    }
    cout<<ans<<" "<<bns;
    return 0;
}

P1965 转圈游戏

链接

这道题就是每一轮但前人走到$(m+x)%n$的位置,而$10^k* m$轮则会走到

$(m* 10^k+x)%n$的位置,而这可以用快速模幂来算

#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cmath>
#include<queue>
#include<stack>
#include<vector>
#include<map>
#include<string>
#include<cstring>
#define int long long int
using namespace std;
inline int read() {
    char c = getchar();
    int x = 0, f = 1;
    while(c < '0' || c > '9') {
        if(c == '-') f = -1;
        c = getchar();
    }
    while(c >= '0' && c <= '9') x = x * 10 + c - '0', c = getchar();
    return x * f;
}
int n,m,k,x;
int quick_pow(int x,int y,int z) {
    int ans=1;
    while(y) {
        if(y&1){
            ans=ans*x%z;
            ans%=z;
        } 
        x=x*x%z;//注意这里!!!!!!
        y>>=1;
    }
    return ans%z;
}
signed main() {
    freopen("circle.in","r",stdin);
    freopen("circle.out","w",stdout);
    cin>>n>>m>>k>>x;
    int circle=quick_pow(10,k,n)%n;
    cout<<(x%n+m%n*circle%n)%n;
    return 0;
}

P1098 字符串的展开

链接

题目不难就是有几个坑

1.倒序时的循环 如:倒序时3-5(应为345)

2.连续‘-’ (可能会少一个或出现什么奇怪的东西)如:2---9a-b(应为2---9ab)//lzt就是被这里坑死的

#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cmath>
#include<queue>
#include<stack>
#include<vector>
#include<map>
#include<string>
#include<cstring>
using namespace std;
inline int read() {
    char c = getchar();
    int x = 0, f = 1;
    while(c <'0'|| c >'9') {
        if(c =='-') f =-1;
        c = getchar();
    }
    while(c >='0'&& c <='9') x = x * 10 + c -'0', c = getchar();
    return x * f;
}
int p1,p2,p3;
void doit(char l, char r) {
    if (l>=r||(isdigit(l)&&isalpha(r))||(isdigit/*数字*/(r)&&isalpha/*字母*/(r))) {
        printf("-", l, r);
    } else if (l-r==-1) {
        return ;
    } else {
        if ((l>=65&&l<=90)||(l>=97&&l<=122)) {
            if (p1==1) {
                l=tolower(l);
                r=tolower(r);
            } else if (p1==2) {
                l=toupper(l);
                r=toupper(r);
            }
        }
        /*正序*/
        if (p3==1) {
            for (char i=l+1; i<r; i++) {
                for (int n=0; n<p2; n++) {
                    if(p1==3) {
                        cout<<'*';
                    } else {
                        cout<<i;
                    }
                }
            }
        }
        /*倒序*/
        else if(p3==2) {
            for (char i=r-1; i>l; i--) {
                for (int n=0; n<p2; n++) {
                    if(p1==3) {
                        cout<<'*';
                    } else {
                        cout<<i;
                    }
                }
            }
        }
    }
}
int main() {
    freopen("expand.in","r",stdin);
    freopen("expand.out","w",stdout);
    cin>>p1>>p2>>p3;
    string s;
    cin>>s;
    char l;
    int expand;
    for(int i = 0; i < s.size(); i++) {
        if (s[i]=='-') {
            printf("-");
        } else {
            expand=i;
            break;
        }
    }
    for(int i=expand; i<s.size(); i++) {
        if(s[i]!='-') {
            cout<<s[i];
        } else if(i+1==s.size()||(i+1!=s.size()&&s[i+1]=='-')||(l=='-')) {
            cout<<"-";
        } else {
            doit(l,s[i+1]);
        }
        l=s[i];
    }
    return 0;
}

猜你喜欢

转载自www.cnblogs.com/pyyyyyy/p/10900206.html