CCPC-Wannafly Winter Camp Day 1

B. Cryptography

Meaning of the questions:

Tell you about the string encryption method, and then give you some encrypted string operations and encryption, so you find the original string

Ideas:

Know the encrypted string can be encrypted character string before the launch forward is encrypted, we can continue to move forward simulation

#include<iostream>
#include<algorithm>
#include<cstring>
#include<cstdio>
 using namespace std;
 const int maxn=1020;
char s[maxn][105];
 int b[maxn][105];
 struct node{
     int x,y;
 } A [Max];
 int n,m,len[maxn],tem[105];
void repair(int x,int y) {
     for(int i=0;i<len[y];i++) tem[i]=b[x][(i%len[x])];
    for(int i=0;i<len[y];i++) b[y][i] = (b[y][i]-tem[i]+52) % 52;
}

int main () {
    cin>>n>>m;
    for(int i=m;i>=1;i--) cin>>a[i].x>>a[i].y;
     for(int i=1;i<=n;i++){
         cin>>s[i];
         len[i]=strlen(s[i]);
     }
    for(int i=1;i<=n;i++){
        for(int j=0;j<len[i];j++){
            if(s[i][j]>='a'&&s[i][j]<='z')
                b[i][j]=s[i][j]-'a';
            else if(s[i][j]>='A'&&s[i][j]<='Z')
                b[i][j]=s[i][j]-'A'+26;
        }
    }
     for(int i=1;i<=m;i++)repair(a[i].x,a[i].y);
    for(int i=1;i<=n;i++){
        for(int j=0;j<len[i];j++){
            if(b[i][j]>=0&&b[i][j]<=25)
                s[i][j]=b[i][j]+'a';
            else if(b[i][j]>=26&&b[i][j]<=51)
                s[i][j]=(b[i][j]-26)+'A';
        }
    }
    for(int i=1;i<=n;i++)
        cout<<s[i]<<endl;
    return 0;    
  } 

H. greatest common divisor

Ideas:

From the start multiplicative k and k is a multiple of the number of primes

Remember to use large numbers! ! Did not find several hair burst WA

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

int t,n,k;
string ans,str;
void initial(string &a, string &b){
    while (a.size()<b.size())a = '0' + a;
    while (b.size()<a.size())b = '0' + b;
}
//打印
void print(string &a, string &b){
    cout << a << endl;
    cout << b << endl;
}
// find the maximum string 
void FindMax ( String & A, String & B) {
     String tmp;
     IF (A < B) {
        tmp = b;
        b = a;
        a = tmp;
    }
}
// delete the first character '0' 
BOOL del ( String & A ) {
     IF (A [ 0 ] == ' 0 ' ) {
        a.erase(0, 1);
        return true;
    }
    else 
        return  false ;
}
// delete all previous 0 
void delAllZroe ( String & A ) {
     the while (del (A)) {
        of the);
    };
}
// large numbers addition 
String bigItergeAdd ( String A, String B) {
    initial(a, b);
    a = '0' + a;
    b = '0' + b;
    for (int i = a.size() - 1; i >= 0; i--){
        int num1 = a[i] - '0';
        int num2 = b[i] - '0';
        if (num1 + num2>9){
            a[i - 1] = a[i - 1] - '0' + 1 + '0';
            a[i] = (num1 + num2) - 10 + '0';
        }
        else{
            a[i] = (num1 + num2) + '0';
        }
    }
    of the);
    //    cout<<a<<endl;
    return a;
}
// large numbers subtraction 
String bigItergeSub ( String A, String B) {
    initial(a, b);
    findMax(a, b);
    for (int i = a.size() - 1; i >= 0; i--){
        int num1 = a[i] - '0';
        int num2 = b[i] - '0';
        if (num1<num2){
            a[i - 1] = a[i - 1] - '0' - 1 + '0';
            a[i] = (num1 + 10 - num2) + '0';
        }
        else{
            a[i] = (num1 - num2) + '0';
        }
    }
    of the);
    //    cout<<a<<endl;
    return a;
}
// large number multiplication (addition of large numbers to achieve) 
String bigItergeMul ( String A, String B) {
    delAllZroe (a);
    delAllZroe (b);
    initial(a, b);
    findMax(a, b);
    string res = "0";
    int count = 0;
    delAllZroe (b);
    for (int i = b.size() - 1; i >= 0; i--){
        int num1 = b[i] - '0';
        if (i != b.size() - 1)        a = a + '0';
        for (int i = 1; i <= num1; i++){
            nothing = bigItergeAdd (naught);
        }
    }
    delAllZroe (res);
    return res;
}

bool prime(int x)
{
    for(int i=2;i<=sqrt(x);i++)
    {
        if(x%i==0) return false;
    }
    return true;
 } 
int main ()
{
    cin>>t;
    while(t--)
    {
        cin>>n>>k;
        int temp=k;
        ans="";
        while(temp)
        {
            years + = temp% 10 + ' 0 ' ;
            temp/=10;
        }
        reverse (ans.begin () ans.end ());
        for(int i=2;i*k<=n;i++)
        {
            if(prime(i))
            {
                str="";
                temp=i;
                while(temp)
                {
                   str + = temp% 10 + ' 0 ' ;
                   temp/=10;
                }
              //  cout<<str<<endl;
                reverse(str.begin(),str.end());
                years = bigItergeMul (years, str);
            }
        }
        
        cout<<ans<<endl;
    }        
}

F. multiplication

Meaning of the questions:

You give a two arrays a, C b matrix multiplication constituted of Matrix large number of the first K

Ideas:

B first array is sorted, and then from the bipartite 1e12 -1e12 to answer a particular attention in the array is less than half of the array b 0, and a is equal to 0 when element

#include<iostream>
#include<algorithm>
#include<cstdio>
const int maxn=1e5+10;
using namespace std;
typedef long long ll;
 ll a[maxn],b[maxn];
 int n,m;
 ll ans,k;
 ll find(ll temp,ll x)
 {
     int l=1,r=m,mid,ret;
         if(x>0){
             ret=m+1;
             while(l<=r){
                 mid=(l+r)>>1;
                 if(b[mid]*x>=temp)    r=(ret=mid)-1;
                 else    l=mid+1;
             }
             return m-ret+1;
         }
        else if(x<0){
            ret=0;
            while(l<=r){
                mid=(l+r)>>1;
                if(b[mid]*x>=temp)    l=(ret=mid)+1;
                else r=mid+1;
            }
            Return the right;
        }
}
 ll  judge(ll mid)
 {
     ll cnt=0;
     for(int i=1;i<=n;i++){
         if(a[i]==0)
             cnt+=(0>=mid)*m;
         else
             cnt+=find(mid,a[i]);
     }
    return cnt;
 }
 int main ()
 {
     scanf("%d%d%lld",&n,&m,&k);
     for(int i=1;i<=n;i++) scanf("%d",&a[i]);
     for(int i=1;i<=m;i++) scanf("%d",&b[i]);
     sort(b+1,b+1+m);
     ll l=-1e12,r=1e12;
     while(l<=r){
         ll mid=(l+r)/2;
         if(judge(mid)>=k)    l=(ans=mid)+1;
         else r=mid-1;
     }
    cout<<ans<<endl;
 }

Guess you like

Origin www.cnblogs.com/overrate-wsj/p/12185331.html