2025 2.17-2.23 week 4
2.17-2.23 week 4
-
前言
-
补题
- 蓝桥杯训练赛 3
-
总结
1.前言
寒假训练结束了。整体训练效果不好,放假的环境容易松懈,在学校的效率还是很高的,开学后不会再懈怠。
2.补题
1.蓝桥杯训练赛 3
P10900 [蓝桥杯 2024 省 C] 数字诗意
题意:给n个数,依次判断这些数字是不是由连续的正整数相加而得,输出不具有诗意的个数。
思路:
对于一个数ai,由题知可以将具有诗意的条件转换成满足下面的式子:
\[2ai=(m+n)(m-n+1) \] 而(m+n)+(m-n+1)=2m+1一定是奇数,所以(m+n)和(m-n+1)的奇偶性一定不同;
ai是偶数,而奇数乘偶数还是偶数;
所以不满足这个式子的「偶数等于两个偶数相乘」的情况,只有2的幂了。
#include<bits/stdc++.h>
using namespace std;
#define endl '\n'
#define int long long
void solve(){
int n;cin>>n;
vector<int>a(200005,0);
int count=0;
for(int i=0;i<n;i++){
cin>>a[i];
if(log2(a[i])==0||log2(a[i])-floor(log2(a[i]))==0){
count++;
}
}
cout<<count;
}
signed main() {
ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
int t;t=1;
while(t--){
solve();
}
return 0;
}
P9231 [蓝桥杯 2023 省 A] 平方差
题意:给出L,R,求是否存在x,y,z(x,y,z∈[L,R]),使得x=y2-z2。
思路:
平方差可得
\[x=(y+z)(y-z)
\]
(y+z)和(y-z)奇偶性相同,所以如果x是偶数就拆成x/2和2,x是奇数就拆成1和本身。
所以x一定是四的倍数或奇数。
#include<bits/stdc++.h>
using namespace std;
#define endl '\n'
#define int long long
void solve(){
int l,r;cin>>l>>r;
int count=0;
for(int i=l;i<=r;i++){
if(i%2!=0||i%4==0){
count++;
}
}
cout<<count;
}
signed main() {
ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
int t;t=1;
while(t--){
solve();
}
return 0;
}
小结:在补的时候太过于关注式子右侧了。
P8700 [蓝桥杯 2019 国 B] 解谜游戏
题意:能否通过任意次操作,使得内层全是黄色,中层全是红色,上层全是绿色。
思路:内,中,上层分别有4,8,12根塑料棒,是成倍数关系的,且每次转动是所有层一起同方向转,可以发现内层的任一根塑料棒,可以对应的中、外层塑料棒是固定的那五个。只要这一共六根塑料棒颜色的黄红绿分别不超过1,2,3,那怎么调都能调成期望的形态。
#include<bits/stdc++.h>
using namespace std;
#define endl '\n'
#define int long long
void solve(){
string a,b,c;cin>>a>>b>>c;
for(int i=0;i<4;i++){
int temp[300]={0};
temp[c[i]]++;
temp[b[i]]++;
temp[b[i+4]]++;
temp[a[i]]++;
temp[a[i+4]]++;
temp[a[i+8]]++;
if(temp['Y']>1||temp['R']>2||temp['W']>3){
cout<<"NO"<<endl;
return;
}
}
cout<<"YES"<<endl;
}
signed main() {
ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
int t;cin>>t;
while(t--){
solve();
}
return 0;
}
3.总结
在网上看到的有关部分数据类型的数量级贴到这里
| 类型名称 | 取值范围 | 大小 | 数量级 |
|---|---|---|---|
| int | -231~(231-1) | 231=2,147,483,648 | 109数量级 |
| unsigned int | 0~(232-1) | 232=4,294,967,296 | 109数量级 |
| long long (_int64) | -263~(263-1) | 263=9,223,372,036,854,775,808 | 1018数量级 |
| unsigned long long (unsigned_int64) | 0~(264-1) | 264=18,446,744,073,709,551,616 | 1019数量级 |
所以说其实开longlong就能处理大部分数据了

浙公网安备 33010602011771号