蓝桥杯-牛客冲刺题单
- 前言:
- 牛牛的早八
- 光速签到
- 牛牛的身高
- A加B,A模B
- 四舍五入
- 小红的环形字符串
- 牛牛的说谎机器
- 传送阵
- 优美的序列
- 小d和超级泡泡堂
- qsgg and Subarray
- 结语
前言:
蓝桥杯前一天除了看看模板和做过的题,也可以限时做一下中等偏下的题找手感。
链接: 冲刺题单
链接: b站up主也有讲解
牛牛的早八
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define endl '\n'void solve()
{int m;cin >> m;//cout<<"m="<<m<<endl;int a = 0, b = 0;while (m--){int x, y;scanf("%lld:%lld", &x, &y);//cout<<"x="<<x<<' '<<"y="<<y<<endl;int time = x * 60 + y;//cout<<"time="<<time<<endl;if (time > 480 && time <= 485)a++;else if (time > 485)b++;}cout << a << ' ' << b << endl;}signed main()
{int t = 1;cin >> t;while (t--)solve();return 0;
}
光速签到
#include<bits/stdc++.h>
using namespace std;
#define int long long const int N = 10;
int v[N];
int n;
int flag;
int res;bool cmp(int x, int y)
{return x > y;
}signed main()
{cin >> n;for (int i = 0; i < n; i++)cin >> v[i];sort(v, v + n, cmp);for (int i = 0; i < n; i++){if (v[i] != 0){flag = 1;break;}}if (!flag){for (int i = 0; i < n; i++){cout << v[i];}return 0;}for (int i = 0; i < n; i++){res = res * 10 + v[i];}if (res % 10 == 0) cout << res;else cout << -1;return 0;}
牛牛的身高
#include<bits/stdc++.h>
using namespace std;
#define int long long int n;void solve()
{cin >> n;while (n--){string s;cin >> s;reverse(s.begin(), s.end());s.push_back('0');int j = -1;for (int i = 0; i < s.size() - 1; i++){if (s[i] >= '5'){s[i + 1]++;j = i;}}for (int i = 0; i <= j; i++){s[i] = '0';}if (s.back() == '0')s.pop_back();reverse(s.begin(), s.end());cout << s << endl;}
}signed main()
{int t = 1;//cin>>t;while (t--)solve();return 0;
}
A加B,A模B
#include<bits/stdc++.h>
using namespace std;
#define int long long signed main()
{int t;cin >> t;while (t--){int n, m;cin >> n >> m;if (n > 2 * m){cout << m << ' ' << n - m << endl;}else{cout << -1;}}return 0;
}
四舍五入
#include<bits/stdc++.h>
using namespace std;
#define int long long signed main()
{int n;cin >> n;int m = n % 10;int k = n / 10;if (m >= 5){cout << (k + 1) * 10;}else{cout << k * 10;}return 0;
}
小红的环形字符串
#include<bits/stdc++.h>
using namespace std;
#define int long long signed main()
{string s, a;cin >> s >> a;int n = s.size();s += s;int i = 0;int res = 0;while ((i = s.find(a, i)) != -1 && i < n){res++;i++;}cout << res;return 0;
}
牛牛的说谎机器
#include<bits/stdc++.h>
using namespace std;
#define int long long const int N = 1e6 + 10;
int v[N];
int res;int n, m;
signed main()
{cin >> n >> m;for (int i = 0; i < m; i++){int a, b, c;cin >> a;if (a == 1){cin >> b >> c;v[1]++;v[b]--;v[c + 1]++;v[n + 1]--;}else{cin >> b;if (a == 2){v[1]++;v[b]--;}else{v[b + 1]++;v[n + 1]--;}}}for (int i = 1; i <= n; i++)v[i] += v[i - 1];int mx = 0;for (int i = 1; i <= n; i++){mx = max(mx, v[i]);}for (int i = 1; i <= n; i++){if (v[i] == mx)res++;}cout << mx << " " << res;return 0;}
传送阵
#include<bits/stdc++.h>
using namespace std;
#define int long long
const int N=1e6;
int a[N];
int n,m;signed main()
{int t;cin>>t;while(t--){cin>>n>>m;map<int,int>mp;int res=0;for(int i=0;i<n;i++){for(int j=0;j<m;j++){int a;cin>>a;if(mp[a]==0){mp[a]++;res++;}}}cout<<res<<endl;}return 0;
}
优美的序列
#include<bits/stdc++.h>
using namespace std;
#define int long long
const int N=1e5;
int v[N];signed main()
{int t;cin>>t;while(t--){int n;cin>>n;for(int i=0;i<n;i++)cin>>v[i];sort(v,v+n);int flag =1;for(int i=0;i<n-1;i++){if(abs(v[i]-v[i+1])<1){flag=0;break;}}if(!flag)cout<<-1<<endl;else{for(int i=0;i<n;i++){cout<<v[i]<<" ";}cout<<endl;}}return 0;
}
小d和超级泡泡堂
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define pii pair<int,int>
const int N=1010;
char v[N][N];
int st[N][N];
int n,m;
int res;int dis[4][2]={1,0,-1,0,0,1,0,-1};void dfs(int x,int y)
{st[x][y]=1;queue<pii>q;q.push({x,y});while(q.size()){auto cur=q.front();q.pop();for(int i=0;i<4;i++){int nx=cur.first+dis[i][0];int ny=cur.second+dis[i][1];if(nx<0||nx>=n||ny<0||ny>=m)continue;if(st[nx][ny])continue;if(v[nx][ny]=='#')continue;if(v[nx][ny]=='!')res++;st[nx][ny]=1;q.push({nx,ny});}}
}signed main()
{cin>>n>>m;int a,b;for(int i=0;i<n;i++){for(int j=0;j<m;j++){cin>>v[i][j];if(v[i][j]=='@'){a=i;b=j;}}}dfs(a,b);cout<<res;
}
qsgg and Subarray
#include<bits/stdc++.h>
using namespace std;
#define int long long
const int N = 1e6 + 10;
int v[N], a[N];
int n;
int res;
signed main()
{cin >> n;for (int i = 1; i <= n; i++)cin >> a[i];for (int i = 1; i <= n; i++){int mi = 1e9;for (int j = 0; j < 32; j++){if (((a[i] >> j) & 1) == 0)v[j] = i;//如果该位是0,那么赋值//如果该位是1,那么不操作 }for (int j = 0; j < 32; j++){mi = min(mi, v[j]);}//cout<<mi<<endl;res += mi;}cout << res;return 0;
}
结语
祝各位都能拿奖!
……无论获奖与否,其实在备赛过程中逼着自己学习的知识更是难得可贵的。
共勉~