第十五届蓝桥杯C/C++C组省赛真题
#include<bits/stdc++.h>
#define int long long
using namespace std;
signed main()
{
int a = 7385137888721;
int b = 10470245;
int res = pow(a , 0.5);
cout << res * 2 << endl;
}
//5435122
没有log.txt
//找规律,发现只有 2^n无法表示出来
#include <bits/stdc++.h>
#define int long long
using namespace std;
const int N = 2e5 + 10;
int n;
int a[N];
int ans;
signed main()
{
ios::sync_with_stdio(0);
cin.tie(0); cout.tie(0);
cin >> n;
for(int i = 1; i <= n; i ++) cin >> a[i];
for(int i = 1; i <= n; i ++)
for(int j = 0; j <= 64; j ++)
if(pow(2,j) == a[i])
ans ++;
cout << ans << endl;
return 0;
}
#include <bits/stdc++.h>
#define int long long
#define x first
#define y second
using namespace std;
typedef pair<int , int> PII;
const int N = 2e5 + 10;
int n;
PII p[N]; //p[i].x存储图形个数,p[i].y存储原本的数字
int check(int m)
{
int cnt = 0;
while(m)
{
int t = m % 10;
if(t == 0 || t == 4 || t == 6 || t == 9) cnt ++;
if(t == 8) cnt += 2;
m /= 10;
}
return cnt;
}
signed main()
{
ios::sync_with_stdio(0);
cin.tie(0); cout.tie(0);
cin >> n;
for(int i = 1; i <= n; i ++)
{
cin >> p[i].y;
p[i].x = check(p[i].y);
}
sort(p + 1 , p + 1 + n);
for(int i = 1; i <= n; i ++) cout << p[i].y << " ";
return 0;
}
#include<bits/stdc++.h>
#define int long long
using namespace std;
const int N = 1e6 + 10;
int n;
int a[N]; //原数组
int b[N]; //差距数组
signed main()
{
ios::sync_with_stdio(0);
cin.tie(0); cout.tie(0);
cin >> n;
for(int i = 1;i <= n; i ++)
cin >> a[i];
for(int i = 1;i <= n >> 1; i ++)
b[i] = a[i] - a[n - i + 1];
int res = 0;
for(int i = 1; i <= n >> 1; i ++)
{
res += abs(b[i]);
if(b[i] > 0 && b[i + 1] > 0)
b[i + 1] -= min(b[i] , b[i + 1]);
else if(b[i] < 0 && b[i + 1] < 0)
b[i + 1] -= max(b[i] , b[i + 1]);
}
cout << res << endl;
return 0;
}
#include<bits/stdc++.h>
#define pii pair<int, int>
#define x first
#define y second
using namespace std;
const int N = 3e5 + 10;
int n , m;
int b[N] , s[N];
pii op[N];
int main()
{
ios::sync_with_stdio(0),cout.tie(0),cin.tie(0);
cin >> n >> m;
for(int i = 0; i < m; i ++)
{
int l , r;
cin >> l >> r;
b[l] += 1;
b[r + 1] -= 1;
op[i]={l,r};
}
for(int i = 1; i <= n; i ++)
{
b[i] += b[i - 1];
s[i] = s[i - 1] + (b[i] <= 1);
}
for(int i = 0; i < m; i ++)
cout << s[op[i].y] - s[op[i].x - 1] << '\n';
return 0;
}
#include<bits/stdc++.h>
using namespace std;
const int N = 2e6 + 10;
int main()
{
int n, m;
cin >> n >> m;
vector<int> a(n);
for (int i = 0; i < n; i++)
cin >> a[i];
vector<int> l(N, 0);
vector<int> r(N, 0);
for(int x : a)
{
if(x > 0) r[x] ++;
else if(x < 0) l[-x] ++;
}
for(int i = 1; i < N; i ++)
{
l[i] += l[i - 1];
r[i] += r[i - 1];
}
int res = 0;
for(int i = 1; i <= m; i++)
{
int s = l[i];
if(m - 2 * i > 0) s += r[m - 2 * i];
res = max(res, s);
}
for(int i = 1; i <= m; i ++)
{
int s = r[i];
if(m - 2 * i > 0) s += l[m - 2 * i];
res = max(res, s);
}
for(int x : a)
if(x == 0) res++;
cout << res << endl;
return 0;
}
#include<bits/stdc++.h>
#define int long long
using namespace std;
bool check(string x)
{
int len = x.size();
for(int i = 0; i <= len >> 1; i ++)
{
if(x[i] != x[len - i - 1])
return false;
}
return true;
}
signed main()
{
ios::sync_with_stdio(0);
cin.tie(0); cout.tie(0);
int t;
cin >> t;
while(t --)
{
string s;
cin >> s;
if(check(s))
{
cout << "Yes\n";
continue;
}
int f = 0;
int len = s.size();
for(int i = 0; i < len; i ++)
{
if(s[i] != 'l' && s[i] != 'q' && s[i] != 'b')
{
f = 1;
break;
}
}
if(!f)
{
cout << "Yes\n";
continue;
}
int id = 0;
for(int i = len - 1; i >= 0; i --)
{
if(s[i] != 'l' && s[i] != 'q' && s[i] != 'b')
{
id = i;
break;
}
}
string tool = "";
for(int i = 0; i <= id; i ++)
tool += s[i];
if(check(tool))
cout << "Yes\n";
else
cout << "No\n";
}
return 0;
}