//A. Minimize!
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int MAX_N = 200000;
void solve() {
int a,b;
cin >>a>>b;
cout<<abs(a-b)<<'\n';
}
int main() {
ios::sync_with_stdio(0);
cin.tie(0);
int t;
cin >> t;
while (t--) {
solve();
}
return 0;
}
//B. osu!mania
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int MAX_N = 200000;
void solve() {
int n;
cin >>n;
stack<int> stk;
int j=n;
while(j--){
string s;
cin >>s;
int l=s.size();
for(int i=0;i<l;i++){
if(s[i]=='#'){
stk.push(i+1);
break;
}
}
}
for(int i=0;i<n;i++){
cout<<stk.top()<<' ';
stk.pop();
}cout<<'\n';
}
int main() {
ios::sync_with_stdio(0);
cin.tie(0);
int t;
cin >> t;
while (t--) {
solve();
}
return 0;
}
//C. The Legend of Freya the Frog
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
void solve() {
long long x, y, k;
cin >> x >> y >> k;
long long steps_x = (x + k - 1) / k;
long long steps_y = (y + k - 1) / k;
long long result;
if (steps_x == steps_y) {
result = steps_x + steps_y;
} else {
result = 2 * max(steps_x, steps_y) - 1;
if(steps_x<steps_y)result++;
}
cout << result << '\n';
}
int main() {
ios::sync_with_stdio(0);
cin.tie(0);
int t;
cin >> t;
while (t--) {
solve();
}
return 0;
}
//D. Satyam and Counting
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
void solve() {
int n;
ll ans=0;
cin >>n;
vector<vector<int>> arr(2,vector<int>(n+1,0));
for(int i=0,a,b;i<n;i++){
cin >>a>>b;
arr[b][a]=1;
}
for(int i=0;i<=n;i++){
if(arr[0][i]&&arr[1][i]){
ans+=n-2;
}
if(i>=2){
if(arr[0][i]&&arr[0][i-2]&&arr[1][i-1])ans++;
if(arr[1][i]&&arr[1][i-2]&&arr[0][i-1])ans++;
}
}cout<<ans<<'\n';
}
int main() {
ios::sync_with_stdio(0);
cin.tie(0);
ll t;
cin >>t;
while(t--)
solve();
return 0;
}
//E. Klee's SUPER DUPER LARGE Array!!!
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
void solve() {
ll n, k;
cin >> n >> k;
ll l = k;
ll r = k + n - 1;
ll ans = LLONG_MAX;
while (l <= r) {
ll m = (l + r) / 2;
ll ml = (k+m)*(m-k+1) / 2;
ll mr = (m+1+k+n-1)*(n-(m-k+1)) / 2;
ll diff = abs(ml - mr);
ans = min(ans, diff);
if (ml < mr) {
l = m + 1;
} else if (ml > mr) {
r = m - 1;
} else {
ans = 0;
break;
}
}
cout << ans << '\n';
}
int main() {
ios::sync_with_stdio(0);
cin.tie(0);
int t;
cin >> t;
while (t--) {
solve();
}
return 0;
}
Codeforces Round 971 (Div. 4) A~E
于 2024-09-04 15:54:03 首次发布