2020牛客暑期多校训练营(第四场)
生活随笔
收集整理的這篇文章主要介紹了
2020牛客暑期多校训练营(第四场)
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
2020牛客暑期多校訓練營(第四場)
這場屬實有點難受
文章目錄
- A Ancient Distance
- B Basic Gcd Problem
- 題目
- 代碼:
- C Count New String
- D Dividing Strings
- E Eliminate++
- F Finding the Order
- 題意:
- 題解:
- 代碼:
- G Geometry Challenge
- H Harder Gcd Problem
- I Investigating Legions
- J Jumping on the Graph
A Ancient Distance
B Basic Gcd Problem
爺被卡自閉了
題目
仔細分析題其實就是問cf(x)等于等于多少
而f(x)等于什么呢?
唯一分解定理
而我們要做的就是求出f(x)=a1+a2+a3+…an
pow(c,sum)
我被int和longlong卡了,快速冪我用的longlong結果超時了
其實思路不難,多注意細節
代碼:
#include <iostream> #include <stdio.h> #include<vector> #include<queue> #include<math.h> #include<algorithm> #include<string.h> using namespace std; typedef long long ll; const int maxn=1e6+3; const ll mod=1e9+7; ll sum=0; ll spr[maxn],zs[maxn],ds[maxn]; inline ll poww(ll a,ll b,ll p) {ll res=1;ll base=a%p;while(b){if(b&1){res=(res*base)%p;}base=( base*base)%p;b>>=1;}return res%p; } //template <typename T> //inline void read(T &s){ // T t=1; char k=getchar(); s=0; // for (;k<'0'||k>'9';k=getchar()) if (k=='-') t=-1;//判斷該數正負 // for (;k>='0'&&k<='9';k=getchar()) s=(s<<1)+(s<<3)+(k^48);//<<1加上<<3就相當于*10,但是位運算的速度較快,^48也相當于-‘0’,同理,較快。 // s*=t; //} //void olp(){ //先打表,歐拉篩 // memset(is,true,sizeof is); // is[0] = is[1] = 0; // for(int i=2;i<maxn;i++){ // if(is[i]) spr[cnt++]= i; // for(int j=0;i*spr[j]<maxn&&j<cnt;j++){ // is[i*spr[j]] = 0; // if(i%spr[j]==0) break; // } // } //} void fj(int x){ //不同素數的個數for(int i=2;i*i<=x;i++){while(x%i==0){x/=i,sum++; }}if(x!=1){ //如果分解玩x都不等于1,那么x必定是一個素數sum++;}return ; } int main(){//olp();int t;scanf("%d",&t);while(t--){ll n,c;scanf("%lld%lld",&n,&c);// cout<<n<<" "<<c<<endl;sum=0;fj(n);ll ww=poww(c,sum,mod);printf("%lld\n",ww);}return 0; }C Count New String
D Dividing Strings
E Eliminate++
F Finding the Order
題意:
兩條平行直線,上一條是ab(a在左邊,b在右邊),下一條是dc(但是d和c誰在左誰在右未知)
現在給你,ac,ad,bc,bd的長度,問d和c誰在左誰在右
題解:
畫圖分析一下
三種情況:cd正常,c很遠,d很遠
圖中是cd的情況
而dc的情況剛好相反
代碼:
#include<bits/stdc++.h> #define rg register using namespace std; // scanf("%d",); // printf("%d",); int gcd(int a,int b) {if(b==0)return a;else return gcd(b,a%b); } inline int read(){int s=0,w=1;char ch=getchar();while(ch<'0'||ch>'9'){if(ch=='-')w=-1;ch=getchar();}while(ch>='0'&&ch<='9') s=s*10+ch-'0',ch=getchar();return s*w; } int main() {int t;t=read();while(t--){int ac=read(),ad=read(),bc=read(),bd=read();if(ac<=ad&&bc>=bd){printf("AB//CD\n");}else if(ac>=ad&&bc>=bd&&ac<bc){printf("AB//CD\n");}else if(ac<=ad&&bc<=bd&&ad>bd){printf("AB//CD\n");}else printf("AB//DC\n");}return 0; }//printf("AB//CD\n"); //printf("AB//DC\n");G Geometry Challenge
H Harder Gcd Problem
I Investigating Legions
J Jumping on the Graph
總結
以上是生活随笔為你收集整理的2020牛客暑期多校训练营(第四场)的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: PS5 将迎发售三周年纪念,索尼宣布平台
- 下一篇: 牛客算法周周练15