Codeforces Round 964 (Div. 4)
A送分
B
大意:两个人两张牌 随机翻 求a翻出来的牌比b大的可能
#include <cstdio>
#include <cmath>
#include <algorithm>
#include <iostream>
#include <cstring>
#include <vector>
#define ep emplace_back
using namespace std;
void solve() {
int ans = 0;
int a1, b1, a2, b2;
cin >> a1 >> a2 >> b1 >> b2;
int cnt1 = 0, cnt2 = 0;
if (a1 > b1)
cnt1++;
else if (a1 < b1)
cnt2++;
if (a2 > b2)
cnt1++;
else if (a2 < b2)
cnt2++;
if (cnt1 > cnt2)
ans += 2;
cnt1 = cnt2 = 0;
if (a1 > b2)
cnt1++;
else if (a1 < b2)
cnt2++;
if (a2 > b1)
cnt1++;
else if (a2 < b1)
cnt2++;
if (cnt1 > cnt2)
ans += 2;
cout << ans << "\n";
}
int main() {
int T = 1;
cin >> T;
while (T--) {
solve();
}
return 0;
}
C
题目大意:有些区间被阻断 找连续的区间 判断最长的长度能否大于S
思路:保证l,r是不相交的 扫一遍所有的区间就好了 跑两个指针 pos1=0,pos2=l
#include<iostream>
using namespace std;
void solve(){
int n,s,m;
scanf("%d%d%d",&n,&s,&m);
bool ok=0;
int pos=0;
for(int i = 0; i < n; ++i){
int l,r;
scanf("%d%d",&l,&r);
int k = l-pos;
if( k>=s )
ok=1;
pos=r;
}
if(m-pos>=s) ok=1;
if(ok) cout<<"YES";
else cout<<"NO";
cout<<"\n";
}
int main(){
int T;
cin>>T;
while(T--){
solve();
}
}
D
题目大意:给定字串字符s t s某些字符可以修改 能否通过修改s st t是s子序列
思路:两个指针扫一遍,? 或者能匹配就让第二个指针往前跑,最后判断第二个指针跑到尾了
#include <iostream>
#include <string>
#include <vector>
#include <unordered_set>
using namespace std;
void solve(){
string s,t;
cin>>s>>t;
int j=0;
for(int i = 0; i < s.size(); ++i){
if(s[i] == '?' ){
if(j < t.size()){
s[i] = t[j];
++j;
}
else {
s[i] = 'a';
}
}
else if( s[i] == t[j] and j<t.size()){
++j;
}
}
if(j == t.size()) cout<<"YES"<<"\n"<<s;
else cout<<"NO";
cout<<"\n";
}
int main(){
int _;
cin>>_;
while(_ --){
solve();
}
}
E:
题意:写下L,L+1,...R-1,R个数字,操作他,让一个数乘以三,另一个除以三。直到所有为0 求最小的操作次数
思路:先让L为0 ans 加上操作次数 观察到[3,8] opt=2,[9,26]opt=3 只需要计算区间长度乘以区间对应的opt次数就可
#include <iostream>
#include <cmath>
#include <cstdio>
#define lld long long
using namespace std;
int f(int x){
int ans=0;
while(x!=0){
x/=3;
ans++;
}
return ans;
}
void solve(){
int L,R;
cin>>L>>R;
int K = f(L);
int M = f(R);
lld ans=0;
int a[50],b[50];
for(int i=0;i<=32;++i){
a[i] = pow(3,i);
b[i] = pow(3,i+1)-1;
}
ans+=2*f(L);
int pos=L+1;
for(int i=f(L+1) ; i <= M; ++i){
//printf("ans=%d ",ans);
int pos2 = b[i-1];
if(pos2>R){
pos2=R;
//printf("pos=%d pos2=%d \n",pos,pos2);
ans+=(pos2-pos+1)*i;
break;
}
else {
//printf("pos=%d pos2=%d \n",pos,pos2);
ans+=(pos2-pos+1)*i;
pos = a[i];
}
}
cout<<ans<<"\n";
}
int main(){
int T;
cin>>T;
while(T--){
solve();
}
}
// 2 3 4 5 6 7 8 9 10 11 12
// 1 2 2 2 2 2 2 3 3 3 3
// 14+12 = 22
F:
大意:
思路:
标签:964,int,Codeforces,pos,++,cnt2,ans,Div,include
From: https://www.cnblogs.com/Phrink734/p/18348842