暑假-S组-第八场总结

· · 个人记录

T1

  1. 我们可以发现w[i]只有100,想到用桶存储a[i]出现的次数,再来枚举w,并得出另一个w。
  2. 使用for循环枚举每个可能出现的i。
  3. 最后使用双指针算法找对数。
    #include <bits/stdc++.h>
    using namespace std;
    const int maxn=1e5+7;
    int a[maxn];
    int n;
    int tong[maxn];
    void solve(){   
     int maxx=0;
     for(int w=2;w<=200;w++){
         int cnt=0;
         for(int i=1;i<=100;i++){
             if(w-i>=1){
                 int x=i;
                 int y=w-i;
                 if(x>y){
                     continue;
                 }
                 if(x==y){
                     cnt+=tong[x]/2;
                 }else{
                     cnt+=min(tong[x],tong[y]);
                 }
             }
         }
         maxx=max(maxx,cnt);
     }
     cout<<maxx<<"\n";
    }
    int main(){
     ios::sync_with_stdio(false);
     cin.tie(0);
     cout.tie(0);
     int t;
     cin>>t;
     while(t--){
         cin>>n;
         for(int i=1;i<=n;i++){
             cin>>a[i];
             tong[a[i]]++;
         }
         solve();
         for (int i=1;i<=100;i++){
             tong[i]=0;
         }
     }
     return 0;
    }

    T2

  4. 对于每一个n,要让他的拆分数越小,位数首先要少,也就意味着每一位上的数要紧可能的大。
  5. 对于每一次拆解,从9到2,如果只可以被1整除,直接返回-1。
  6. 如果出现小于10的情况,直接在原有基础上加10.
  7. 最后把每位数从小到大排序,整合输出。
    
    #include <bits/stdc++.h>
    using namespace std;
    #define ll long long 
    ll solve(ll x){
     if(x<10){
         return x+10;    
     } 
     vector<int>nums;
     while(x>9){
         bool flag=false;
         for(int i=9;i>=2;i--){
             if(x%i==0){
                 flag=true;
                 nums.push_back(i);
                 x/=i;
                 break;
             }
         }
         if(!flag){
             return -1;
         }
     }
     nums.push_back(x);
     sort(nums.begin(),nums.end());
     ll ans=0;
     for(int i=0;i<nums.size();i++){
         ans=ans*10+nums[i];
     }    
     return ans;
    }
    int main(){
     int t;
     cin>>t;
     while(t--){
         ll n;
         cin>>n;
         cout<<solve(n)<<endl;
     }
     return 0;
    }
# [T3](https://www.luogu.com.cn/problem/U549508)
1. 对于这题的方位直接磨4即可,在统计每边x和y的值。
2. 再循环t次,求出答案。
```cpp
#include <bits/stdc++.h>
using namespace std;
#define int long long  
const int maxn=5e5+7;
int a[maxn];
int dx[]={-1,0,1,0};
int dy[]={0,1,0,-1};
int n,t;
int sum=0;
signed main(){
    cin>>n>>t;
    for (int i=1;i<=n;i++){
        cin>>a[i];
        sum+=a[i];  
    }
    int pos=0;
    int sx=0;
    int sy=0;
    for(int i=1;i<=n;i++){
        sx+=dx[pos]*a[i];
        sy+=dy[pos]*a[i]; 
        pos=(pos+a[i])%4;
    }
    pos=0;
    int tx=0,ty=0;
    for (int i=1;i<=t;i++){
        pos=(pos+(sum%4))%4;
        if(pos==0){
            tx+=sx; 
            ty+=sy; 
        }
        if(pos==1){
            tx+=sy; 
            ty-=sx; 
        }
        if(pos==2){
            tx-=sx; 
            ty-=sy; 
        }
        if(pos==3){
            tx-=sy; 
            ty+=sx; 
        }
    } 
    cout<<abs(tx)+abs(ty)<<endl;
    return 0;
} 

T4

  1. 这题十分有趣,又是分段二分。
  2. 对于题目所求,我们可以利用唯一分解定理进行简化,n=a[1]^p1+到底。
  3. 但是时间复杂度还是太高了,对于更大的一些数据,我们可以先打出质数表来,再进行和二分。
    #include <bits/stdc++.h>
    using namespace std;
    #define int long long
    const int maxn = 1e5 + 7;
    const int N = 4e4;
    int prime[maxn];
    bool vis[maxn];
    int n, cnt;
    void init(){
     vis[0]=vis[1]=1;
     for(int i=2;i<=N;i++){
         if(!vis[i]){
             prime[++cnt]=i;
             for(int j=i+i;j<=N;j+=i){
                 vis[j]=true;
             }
         }
     }
    }
    void solve(){
     cin>>n;
     int ans=1;
     for (int i=1;i<=cnt;i++){
         int tmp=0;
         while(n%prime[i]==0){
             n/=prime[i];
             tmp++;
             if(tmp==3){
                 tmp=0;
                 ans*=prime[i];
             }
         }
     }
     int l=1;
     int r=1000000;
     while(l<r){
         int mid=(l+r)/2;
         if (mid*mid*mid>=n){
             r=mid;
         }else{
             l=mid+1;
         }
     }
     if(l*l*l==n){
         ans*=l;
     }
     cout<<ans<<"\n";
    }
    signed main(){
     int T;
     cin>>T;
     init();
     while(T--){
         solve();
     }
     return 0;
    }