A. Medium Number
链接 : Problem - 1760A - Codeforces
就是求三个数的中位数 :
#include<bits/stdc++.h>
#define IOS ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define endl '\n'using namespace std;
typedef long long LL;
const int N = 2e5+10;inline void solve(){int a[3];for(int i=0;i<3;i++) cin >> a[i];sort(a,a+3);cout << a[1] << endl;
}int main()
{IOSint _ = 1;cin >> _;while(_ --) solve();return 0;
}
B. Atilla's Favorite Problem
就是求最大字母的长度 (与a的距离)
#include<bits/stdc++.h>
#define IOS ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define endl '\n'using namespace std;
typedef long long LL;
const int N = 2e5+10;int n ;
string s;inline void solve(){cin >> n ;cin >> s;sort(s.begin(),s.end());int ans = (int)(s[n-1]-'a'+1);cout << ans << endl;
}int main()
{IOSint _ = 1;cin >> _;while(_ --) solve();return 0;
}
C. Advantage
链接 : Problem - 1760C - Codeforces
数据范围小的话,随便弄,直接排序之后,求出最大和第二大的值,然后遍历i,求a[i]与除a[i]之外最大值的差距。
#include<bits/stdc++.h>
#define IOS ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define endl '\n'using namespace std;
typedef long long LL;
const int N = 2e5+10;int n ;inline void solve(){cin >> n;vector<int> a(n),b(n);for(int i=0;i<n;i++){cin >> b[i];a[i] = b[i];}sort(b.begin(),b.end());int ma = b[n-1] , mi = b[n-2];for(int i=0;i<n;i++){if(a[i] != ma) cout << a[i] - ma << " ";else cout << a[i] - mi << " ";}cout << endl;
}int main()
{IOSint _ = 1;cin >> _;while(_ --) solve();return 0;
}
D. Challenging Valleys
链接 : Problem - 1760D - Codeforces
题目大概就是说 给出一个数组,如果该数组有且仅有 一个山谷形状的子数组,就输出yes,否则返回false;
这题直接模拟就可以了
#include<bits/stdc++.h>
#define IOS ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define endl '\n'using namespace std;
typedef long long LL;
const int N = 2e5+10;int n;
int a[N],b[N];inline void solve(){cin >> n;for(int i=0;i<n;i++) cin >> b[i];if(n==1){cout << "YES" << endl;return ; }int len = n;n = 0;a[n++] = b[0];//把连续的数去重for (int i = 1; i < len; ++i) {if (b[i] != b[i - 1])a[n++] = b[i];}int cnt = 0;if(n==1 || n==2){cout << "YES" << endl;return ;}if(a[1]>a[0]) cnt ++;if(a[n-2] > a[n-1]) cnt ++;for(int i=1;i<n-1;i++){if(a[i-1]>a[i] && a[i] < a[i+1]){cnt ++;}}if(cnt == 1) cout << "YES" << endl;else cout << "NO" << endl;return ;
}int main()
{IOSint _ = 1;cin >> _;while(_ --) solve();return 0;
}
E. Binary Inversions
链接 : Problem - 1760E - Codeforces
思路 : 要求逆序对的数量最大,那么也就只有三种情况,不改 / 将第一个0改为1 / 将最后的1转换为0, 三种情况分情况讨论即可;
#include<bits/stdc++.h>
#define IOS ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define endl '\n'using namespace std;
typedef long long LL;
const int N = 2e5+10;inline void solve(){int n ; cin >> n;LL ans = 0 , res = 0;vector<int> a(n);for(int i=0;i<n;i++) cin >> a[i];int pre = 0;for(int i=n-1;i>=0;i--){if(a[i]==0) pre++;else ans += pre; // 预处理每个 1 后面 有 多少个 0 之和 }pre = 0;int t = -1;for(int i=0;i<n;i++){if(a[i]==0){// 将第一个 0 转换为 1 t = i;a[i]=1;break;}}for(int i=n-1;i>=0;i--){if(a[i]==0) pre++;else res += pre;}ans = max(ans,res);if(t!=-1) a[t] = 0;res = 0;pre = 0;for(int i=n-1;i>=0;i--){if(a[i]==1){ // 将最后的 1 转换为 0 a[i]=0;break;}}for(int i=n-1;i>=0;i--){if(a[i]==0) pre++;else res += pre;}cout << max(res,ans) << endl;return ;
}int main()
{IOSint _ = 1;cin >> _;while(_ --) solve();return 0;
}
F. Quests
链接 : Problem - 1760F - Codeforces
思路 : 二分求 k 值
/**
* ┏┓ ┏┓
* ┏┛┻━━━┛┻┓
* ┃ ┃
* ┃ ━ ┃
* ████━████
* ◥██◤ ◥██◤
* ┃ ┻ ┃
* ┃ ┃
* ┗━┓ Y ┏━┛
* ┃ S ┃
* ┃ S ┃
* ┃ ┗━━━┓
* ┃ ┣┓
* ┃ ┏┛
* ┗┓┓┏━┳┓┏┛
* ┃┫┫ ┃┫┫
* ┗┻┛ ┗┻┛
*/#include<bits/stdc++.h>
using namespace std;#define int long long
int n,c,d;
int T;
int a[1000050];inline bool check(int k){int now = 1;int res = 0;for(int i=1;i<=d;++i){res+=a[now];++now;if(now == k+2){now = 1;}if(now == n +1){i += k + 1 - n;now = 1;}}return res >= c;
}signed main()
{cin >> T ;while(T--) {cin >> n >> c >> d;for(int i=1; i<=n; ++i) cin >> a[i] ;int sum = 0;sort(a+1,a+n+1);reverse(a+1,a+n+1);bool f = 0;if(a[1] * d < c){puts("Impossible");continue;}if(d <= n){sum = 0;for(int i=1;i<=d;++i){sum+=a[i];}if(sum >= c){f = 1;}}if(f){puts("Infinity");continue;}int res = 0;int l =0;int r =1e16+1;while(l<=r){int mid = l + r >> 1;if(check(mid)){res = mid;l = mid + 1;}else{r = mid - 1;}}if(res == 1e16 + 1){puts("Infinity");continue;}cout<<res<<endl;}return 0;
}
A - Filter
链接 : A - Filter
直接模拟就行了
#include<bits/stdc++.h>
#define IOS ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define endl '\n'using namespace std;
typedef long long LL;
const int N = 2e5+10;inline void solve(){int n ; cin >> n;for(int i=0;i<n;i++){int x ; cin >> x;if(x %2 ==0){cout << x << " ";}}
}int main()
{IOSint _ = 1;// cin >> _;while(_ --) solve();return 0;
}
B - ASCII Art
链接 : B - ASCII Art
也是水题,直接模拟输出即可
#include<bits/stdc++.h>
#define IOS ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define endl '\n'using namespace std;
typedef long long LL;
const int N = 110;int a[N][N];
char s[N][N];inline void solve(){int n,m ;cin >> n >> m;for(int i=0;i<n;i++)for(int j = 0;j<m;j++)cin >> a[i][j];for(int i=0;i<n;i++)for(int j = 0;j<m;j++){if(a[i][j] == 0) s[i][j] = '.';else s[i][j] = (char)('A'+a[i][j]-1);}for(int i=0;i<n;i++){for(int j = 0;j<m;j++){cout << s[i][j]; }cout << endl;}
}int main()
{IOSint _ = 1;// cin >> _;while(_ --) solve();return 0;
}
C - Merge Sequences
链接 : C - Merge Sequences
题意大概是合并两个升序排列的数组,然后求a,b两个数组的元素在新数组中的下标是多少:
这一题直接模拟合并过程即可,在合并的过程中将对应的下标分别添加到ca,cb两个数组中;
#include<bits/stdc++.h>
#define IOS ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define endl '\n'using namespace std;
typedef long long LL;const int N = 1e5+10;
int a[N],b[N];int n,m;inline void solve(){cin >> n >> m;for(int i=1;i<=n;i++) cin >> a[i];for(int i=1;i<=m;i++) cin >> b[i];// a , b 递增 vector<int> ca,cb; int k = 1 ;int p1 = 1 , p2 = 1;while(p1 <= n || p2 <= m){if(p1 == n+1){cb.push_back(k++);p2++;}else if(p2 == m+1){ca.push_back(k++);p1++;}else if(a[p1] < b[p2]){ca.push_back(k++);p1++;}else{cb.push_back(k++);p2++;}}for(int x : ca) cout << x << " ";cout << endl;for(int x : cb) cout << x << " ";cout << endl;
}int main()
{IOSint _ = 1;// cin >> _;while(_ --) solve();return 0;
}
D - Bank
链接 : D - Bank
思路 : 模拟
#include<bits/stdc++.h>
#define IOS ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define endl '\n'using namespace std;
typedef long long LL;
const int N = 5e5+10;int n,q;
int t,x;
bool a[N] = {false}; // 标记 是不是已经 go inline void solve(){cin >> n >> q;int cnt = 1 , now = 1;while(q--){cin >> t;if(t==1){cnt ++;}else if(t==2){cin >> x;// 叫到就一定来了 a[x] = true;}else{while(a[now]) ++now;cout << now << endl;}}
}int main()
{IOSint _ = 1;// cin >> _;while(_ --) solve();return 0;
}
E - 2xN Grid
链接 : E - 2xN Grid
思路 : 也是模拟 , 一一对应即可,和 C 题类似
#include<bits/stdc++.h>
#define IOS ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define endl '\n'using namespace std;
typedef long long LL;
const int N = 1e5+10;LL l,n,m;
LL v1[N],len1[N];//值 和 个数
LL v2[N],len2[N];inline void solve(){cin >> l >> n >> m;for(int i=1;i<=n;i++) cin >> v1[i] >> len1[i];for(int i=1;i<=m;i++) cin >> v2[i] >> len2[i];LL ans = 0;int a = 1 , b = 1;while(a <= n && b <= m){if(v1[a] == v2[b]) ans += min(len1[a] , len2[b]);if(len1[a] < len2[b]){len2[b] -= len1[a];a++;}else{len1[a] -= len2[b];b++;}}cout << ans << endl;
}int main()
{IOSint _ = 1;// cin >> _;while(_ --) solve();return 0;
}