1. 程式人生 > 實用技巧 >2021年藍橋杯第一次訓練賽

2021年藍橋杯第一次訓練賽

A

  • TAG:簽到題

題面及程式碼見校內 第一屆ACM校賽——熱身賽 A題


B

More Info中有詳細的提示,即注意不要讀入行末的換行符,在此不作過多解釋。

  • TAG:檔案讀入相關;簽到題

PZ.cpp

#include<cstring>
#include<iostream>
#include<string>
using namespace std;
int T;
string s;
int main(){
    scanf("%d\n",&T);
    while(T--){
        getline(cin,s);
        cout<<s<<endl;
    }
    return 0;
}

C

  • PZ's solution:

本題題面堅持要求編寫這麼一個函式,說實話,我嫌麻煩,那麼按照題意即可。

注意輸入的元素值均為0的情況即可。

  • TAG:模擬;簽到題

PZ.cpp

#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
int a[10000005];
int CompactIntegers(int s[],int n){
	int i=1,tmp=0;
	for(int i=1;i<=n;++i) if(s[i]!=0) s[++tmp]=s[i];
	for(int i=1;i<=tmp;++i) printf("%d%c",s[i],(i==tmp ? '\n' : ' '));
	return tmp;
}
int main(){
	int n;
	scanf("%d",&n);
	for(int i=1;i<=n;++i) scanf("%d",&a[i]);
	printf("%d",CompactIntegers(a,n));
	return 0;
}

D

  • PZ's solution:

1.對於平面直角座標系下的兩點\((x_1,y_1),(x_2,y_2)\)所構成的直線,若其斜率存在,斜率計算公式為

\[\frac{y_1-y_2}{x_1-x_2} \]

2.當斜率不存在(斜率趨近\(\infty\))時,當且僅當\(x_1-x_2=0\)

3.由於C++允許double型別出現 \(-0.0\) 的運算結果,所以對斜率為\(0\),即\(y_1-y_2=0\)的情況進行特判輸出;

  • TAG:數學;簽到題

PZ.cpp

#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<cmath>
using namespace std;
double x_1,x_2,y_1,y_2;
int main(){
	while(scanf("%lf %lf %lf %lf",&x_1,&y_1,&x_2,&y_2)!=EOF){
		if(x_1-x_2==0) printf("INF\n\n");
		else if(y_1-y_2==0) printf("0.00\n");
		else printf("%.2lf\n\n",(y_1-y_2)/(x_1-x_2));
	}
	return 0;
}

E

  • TAG:模擬;簽到題

PZ.cpp

    #include<iostream>
    #include<cstdio>
    #include<cstring>
    #include<algorithm>
    #include<cmath>
    using namespace std;
    int n,ans;
    int main(){
    	scanf("%d",&n);
    	while(n!=1){
    		++ans;
    		if(n%2==0) n=n/2;
    		else n=(3*n+1)/2;
    	}
    	printf("%d",ans);
    	return 0;
    }

F

  • PZ's solution:

運用短除法,倒序輸出餘數即可,例如:

\(6_{(10)}=110_{(2)}\)

  • TAG:數學;簽到題

PZ.cpp

#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<cmath>
using namespace std;
int a,b,d,res,ans[1000005];
int main(){
	scanf("%d %d %d",&a,&b,&d);
	res=a+b;
	while(res!=0){
		ans[++ans[0]]=res%d;
		res/=d;
	}
	for(int i=ans[0];i>=1;--i) printf("%d",ans[i]);
	return 0;
}

G

  • 快速冪模板,注意p取0或1的情況即可;
  • TAG:快速冪;數學

PZ.cpp

#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<cmath>
using namespace std;
#define int long long
long long a,b,p;
long long qpow(long long x,long long k){
	if(k==0) return 1%p;
	long long res=x; --k;
	while(k){
		if(k&1) res=res*x%p;
		x=x*x%p;
		k>>=1;
	}
	return res;
}
signed main(){
	scanf("%lld %lld %lld",&a,&b,&p);
	printf("%lld",qpow(a,b));
	return 0;
}

賽後總結

1.本次比賽比較基礎,所有集訓隊隊員應該在比賽期間將所有題目盡數AC;

2.對於本次比賽,A~E題比較基礎,其中:

B題考察了ACM競賽中可能出現的讀入陷阱;

C題雖然題面看似要求苛刻,但完成方法很多,如果不是基本語句掌握不熟練,不必強求按照累贅的方法完成本題;

D題考察了ACM競賽中可能出現的輸出陷阱(對於集訓隊隊員來說,這是本次比賽不能犯的錯誤,因為這一陷阱在之前的練習題HDU 3500 Fling出現過);

3.F題考察了進位制轉換,對此不熟悉的同學應該加強練習,進位制運算是演算法競賽中十分常見的內容,而且也是很多演算法的點睛之筆;

4.G題承接自F題,真正考察了一個比較套路的演算法:快速冪,快速冪的理解與進位制轉換密不可分,這裡給出題人點個贊(๑•̀ㅂ•́)و✧;

5.總的來說,為了照顧到所有在校學生,本次比賽的難度是有所剋制的(看看寒假第一次練習賽就知道,難度的差距是天上地下),而集訓隊成員要快速準確完成這些題目,並熟稔於心,向藍橋杯進發!

ps.藍橋杯的歷屆真題,我會去更的,我不想當鴿子,咕咕咕~