A
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
mt19937 rnd(time(0));
#define int long long
typedef tuple<int,int,int> tp;
#define x first
#define y second
typedef pair<int,int> pii;
typedef pair<double,double> pdd;
constexpr int N=1000010,mod=998244353,inf=1e18;
constexpr double pi=3.1415926535897932384626,eps=1e-5;
const ll P=rnd()%mod;
#define all(a) a.begin(),a.end()
#define get_count(x) __builtin_popcount(x)
#define fors(i,a,b) for(int i=a;i<=b;i++)
#define forr(i,a,b) for(int i=b;i>=a;i--)
#define pb(x) push_back(x)
int dx[]={0,1,0,-1,1,1,-1,-1,0};
int dy[]={1,0,-1,1,1,-1,-1,1,0};
int random(int l,int r){
return rand()%r+l;
}
signed main(){
cin.tie(nullptr)->sync_with_stdio(false);
int __=1;
// cin >> __;
while(__--){
int a,b,c,d;
cin >> a >> b >> c >> d;
if(c+d>a+b) cout << "Yes";
else cout << "No";
}
system("color 04");
return 0;
}
B
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
mt19937 rnd(time(0));
#define int long long
typedef tuple<int,int,int> tp;
#define x first
#define y second
typedef pair<int,int> pii;
typedef pair<double,double> pdd;
constexpr int N=1000010,mod=998244353,inf=1e18;
constexpr double pi=3.1415926535897932384626,eps=1e-5;
const ll P=rnd()%mod;
#define all(a) a.begin(),a.end()
#define get_count(x) __builtin_popcount(x)
#define fors(i,a,b) for(int i=a;i<=b;i++)
#define forr(i,a,b) for(int i=b;i>=a;i--)
#define pb(x) push_back(x)
int dx[]={0,1,0,-1,1,1,-1,-1,0};
int dy[]={1,0,-1,1,1,-1,-1,1,0};
int random(int l,int r){
return rand()%r+l;
}
signed main(){
cin.tie(nullptr)->sync_with_stdio(false);
int __=1;
// cin >> __;
while(__--){
int t,t1,t2,d,d1,d2;
cin >> t >> d >> t1 >> d1 >> t2 >> d2;
int ans=inf;
if(d1>=d){
ans=max(0ll,t1-t);
}
if(d2>=d){
ans=min(ans,max(0ll,t2-t));
}
cout << (ans==inf?-1:ans) << '\n';
}
system("color 04");
return 0;
}
C
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
mt19937 rnd(time(0));
#define int long long
typedef tuple<int,int,int> tp;
#define x first
#define y second
typedef pair<int,int> pii;
typedef pair<double,double> pdd;
constexpr int N=1000010,mod=998244353,inf=1e18;
constexpr double pi=3.1415926535897932384626,eps=1e-5;
const ll P=rnd()%mod;
#define all(a) a.begin(),a.end()
#define get_count(x) __builtin_popcount(x)
#define fors(i,a,b) for(int i=a;i<=b;i++)
#define forr(i,a,b) for(int i=b;i>=a;i--)
#define pb(x) push_back(x)
int dx[]={0,1,0,-1,1,1,-1,-1,0};
int dy[]={1,0,-1,1,1,-1,-1,1,0};
int random(int l,int r){
return rand()%r+l;
}
signed main(){
cin.tie(nullptr)->sync_with_stdio(false);
int __=1;
// cin >> __;
while(__--){
int n;
double m;
cin >> n >> m;
int ans=inf;
auto get=[&](int l,int r)->int{
return (r-l+1)*(l+r)/2;
};
int sum=get(1,n);
auto check=[&](int i)->bool{
return 100.0*i/sum>=m;
};
int l=1,r=n+1;
while(l<r){
int mid=l+r>>1;
if(check(mid)) r=mid;
else l=mid+1;
}
cout << (l<=n?l:-1) << '\n';
}
system("color 04");
return 0;
}
D
注意r范围,至少需要开到2e6,也不能太大
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
mt19937 rnd(time(0));
#define int long long
typedef tuple<int,int,int> tp;
#define x first
#define y second
typedef pair<int,int> pii;
typedef pair<double,double> pdd;
constexpr int N=1000010,mod=998244353,inf=1e18;
constexpr double pi=3.1415926535897932384626,eps=1e-5;
const ll P=rnd()%mod;
#define all(a) a.begin(),a.end()
#define get_count(x) __builtin_popcount(x)
#define fors(i,a,b) for(int i=a;i<=b;i++)
#define forr(i,a,b) for(int i=b;i>=a;i--)
#define pb(x) push_back(x)
int dx[]={0,1,0,-1,1,1,-1,-1,0};
int dy[]={1,0,-1,1,1,-1,-1,1,0};
int random(int l,int r){
return rand()%r+l;
}
signed main(){
cin.tie(nullptr)->sync_with_stdio(false);
int __=1;
// cin >> __;
while(__--){
int x,y,w,k;
cin >> x >> y >> w >> k;
auto check=[&](int t)->bool{
int ans=0;
for(int i=1;i<=t;i++){
ans+=i/w;
}
if(t>=x){
ans+=(t-x+1)*y;
}
return ans>=k;
};
int l=0,r=5e6;
while(l<r){
int mid=l+r>>1;
if(check(mid)) r=mid;
else l=mid+1;
}
cout << l << '\n';
}
system("color 04");
return 0;
}
E
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
mt19937 rnd(time(0));
#define int long long
typedef tuple<int,int,int> tp;
#define x first
#define y second
typedef pair<int,int> pii;
typedef pair<double,double> pdd;
constexpr int N=1000010,mod=998244353,inf=1e18;
constexpr double pi=3.1415926535897932384626,eps=1e-5;
const ll P=rnd()%mod;
#define all(a) a.begin(),a.end()
#define get_count(x) __builtin_popcount(x)
#define fors(i,a,b) for(int i=a;i<=b;i++)
#define forr(i,a,b) for(int i=b;i>=a;i--)
#define pb(x) push_back(x)
int dx[]={0,1,0,-1,1,1,-1,-1,0};
int dy[]={1,0,-1,1,1,-1,-1,1,0};
int random(int l,int r){
return rand()%r+l;
}
signed main(){
cin.tie(nullptr)->sync_with_stdio(false);
int __=1;
// cin >> __;
while(__--){
int n,m;
cin >> n >> m;
vector<vector<int>> p(n+1,vector<int>(n+1));
while(m--){
int op,a,b,c;
cin >> op >> a >> b >> c;
if(op==1){
p[a][b]+=c;
}
else p[a][b]-=c;
int ans=0;
for(int i=1;i<=n;i++){
for(int j=1;j<=n;j++){
ans=max(ans,p[i][j]);
}
}
cout << ans << '\n';
}
}
system("color 04");
return 0;
}
F
考虑第i个字母\(a_i\)可以和前面i-1个字母哪些可以构成好的子串,显然是前i-1个字母中\(a_i\)的个数
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
mt19937 rnd(time(0));
#define int long long
typedef tuple<int,int,int> tp;
#define x first
#define y second
typedef pair<int,int> pii;
typedef pair<double,double> pdd;
constexpr int N=1000010,mod=998244353,inf=1e18;
constexpr double pi=3.1415926535897932384626,eps=1e-5;
const ll P=rnd()%mod;
#define all(a) a.begin(),a.end()
#define get_count(x) __builtin_popcount(x)
#define fors(i,a,b) for(int i=a;i<=b;i++)
#define forr(i,a,b) for(int i=b;i>=a;i--)
#define pb(x) push_back(x)
int dx[]={0,1,0,-1,1,1,-1,-1,0};
int dy[]={1,0,-1,1,1,-1,-1,1,0};
int random(int l,int r){
return rand()%r+l;
}
signed main(){
cin.tie(nullptr)->sync_with_stdio(false);
int __=1;
// cin >> __;
while(__--){
string s;
cin >> s;
int n=s.size();
int ans=0;
map<char,int> cnt;
for(int i=0;i<n;i++){
ans+=cnt[s[i]];
cnt[s[i]]++;
}
cout << ans+n << '\n';
}
system("color 04");
return 0;
}
G
n位的数字找到p的倍数,如果n*9<p则,不可能找到p的倍数,则直接输出最小的n位整数即1个1,n-1个0,反之,从后到前依次填p,如果说\(1<=p<=9\),则直接填p,否则填9,因为不能包含前导0,判断一下第一位是不是为0,如果为0,则将这一位变成1,然后从小到大找到\(ans[i]!=0\)的位置index,使得ans[index]--
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
mt19937 rnd(time(0));
#define int long long
typedef tuple<int,int,int> tp;
#define x first
#define y second
typedef pair<int,int> pii;
typedef pair<double,double> pdd;
constexpr int N=1000010,mod=998244353,inf=1e18;
constexpr double pi=3.1415926535897932384626,eps=1e-5;
const ll P=rnd()%mod;
#define all(a) a.begin(),a.end()
#define get_count(x) __builtin_popcount(x)
#define fors(i,a,b) for(int i=a;i<=b;i++)
#define forr(i,a,b) for(int i=b;i>=a;i--)
#define pb(x) push_back(x)
int dx[]={0,1,0,-1,1,1,-1,-1,0};
int dy[]={1,0,-1,1,1,-1,-1,1,0};
int random(int l,int r){
return rand()%r+l;
}
signed main(){
cin.tie(nullptr)->sync_with_stdio(false);
int __=1;
// cin >> __;
while(__--){
int n,p;
cin >> n >> p;
if(n*9<p){
cout << 1 ;
for(int i=1;i<n;i++) cout << 0;
continue;
}
vector<int> ans(n+1);
for(int i=n;i>=1;i--){
if(p>=0&&p<=9){
ans[i]=p;
p=0;
}
else ans[i]=9,p-=9;
}
if(!ans[1]){
ans[1]=1;
for(int i=2;i<=n;i++){
if(ans[i]){
ans[i]--;
break;
}
}
}
for(int i=1;i<=n;i++) cout << ans[i];
}
system("color 04");
return 0;
}
H
计算出一开始\(a>b\)的数量cnt1,\(a<b\)的数量cnt2,则相等的元素有\(d=n-cnt1-cnt2\),分情况讨论,如果\(cnt1>cnt2\),则直接输出0,如果\(cnt1<=cnt2\),优先使\(ai==bi\)的\(ai\)增加1,这样贡献是1,定义\(now=cnt2-cnt1+1\)为cnt1>cnt2需要更改的平局数,如果\(now<=d\)则直接输出now,否则,将\(ai<bi\)的所有位置记录下来,并记录将\(ai>bi\)需要的最小值为多少,进行排序。如果说当cnt1==cnt2时,我们只需要将ai等于bi即可以使得cnt2--,从则满足\(cnt1>cnt2\)
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
mt19937 rnd(time(0));
#define int long long
typedef tuple<int,int,int> tp;
#define x first
#define y second
typedef pair<int,int> pii;
typedef pair<double,double> pdd;
constexpr int N=1000010,mod=998244353,inf=1e18;
constexpr double pi=3.1415926535897932384626,eps=1e-5;
const ll P=rnd()%mod;
#define all(a) a.begin(),a.end()
#define get_count(x) __builtin_popcount(x)
#define fors(i,a,b) for(int i=a;i<=b;i++)
#define forr(i,a,b) for(int i=b;i>=a;i--)
#define pb(x) push_back(x)
int dx[]={0,1,0,-1,1,1,-1,-1,0};
int dy[]={1,0,-1,1,1,-1,-1,1,0};
int random(int l,int r){
return rand()%r+l;
}
signed main(){
cin.tie(nullptr)->sync_with_stdio(false);
int __=1;
// cin >> __;
while(__--){
int n;
cin >> n;
vector<int> a(n+1),b(n+1);
for(int i=1;i<=n;i++) cin >> a[i];
for(int i=1;i<=n;i++) cin >> b[i];
int cnt1=0,cnt2=0;
for(int i=1;i<=n;i++){
if(a[i]>b[i]) cnt1++;
else if(a[i]<b[i]) cnt2++;
}
if(cnt1>cnt2){
cout << 0 << '\n';
}
else{
int d=(n-cnt2-cnt1); //平局数
int now=cnt2-cnt1+1;
if(now<=d){
cout << now << '\n';
}
else{
vector<int> c;
for(int i=1;i<=n;i++){
if(a[i]<b[i]) c.push_back(b[i]-a[i]+1);
}
ranges::sort(c);
cnt1+=d;
int i=0,ans=d;
while(cnt1<=cnt2){
if(cnt1==cnt2){
ans+=c[i++]-1;
break;
}
ans+=c[i++];
cnt1++;
cnt2--;
}
cout << ans << '\n';
}
}
}
system("color 04");
return 0;
}
标签:__,200,typedef,27,int,题解,cin,long,define
From: https://www.cnblogs.com/stability/p/18414786