div4 真的巨卡 YUY
题意:给你一个[1,90]的数 求每个位的 数的和(不知道这样的说法 听得明白吗)
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int n;
void solve()
{
string x;
cin>>x;
int t=x[0]+x[1]-'0'-'0';
cout<<t<<endl;
}
int main()
{
ios::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
int t=1;
cin>>t;
while(t--)
{
solve();
}
return 0;
}
题意:
Suneet 和斯拉夫玩纸牌游戏。游戏规则如下
- 每张牌的整数值介于 1和10 之间。
- 每位玩家收到的 2张牌都是面朝下的(因此玩家不知道自己的牌)。
- 游戏采用回合制,由1个回合组成。在一个回合中,双方随机抽取一张未翻开的牌并翻开。翻开的牌中数字严格意义上更大的一方获胜。如果数字相等,则无人获胜。
- 如果一名玩家赢得的回合数最多(即严格意义上大于另一名玩家),则该玩家赢得游戏。如果相等,则无人获胜。
由于 Suneet 和 Slavic 并不是最好的朋友,您需要计算 Suneet 最终成为赢家的可能性有多少。
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int n;
void solve()
{
int a,b,c,d;
cin>>a>>b>>c>>d;
int sum=0;
if((a>c&&b>=d)||(a>=c&&b>d)) sum+=2;
if((a>d&&b>=c)||(a>=d&&b>c)) sum+=2;
cout<<sum<<endl;
}
int main()
{
ios::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
int t=1;
cin>>t;
while(t--)
{
solve();
}
return 0;
}
题意:
给你n个做事情的时间断([l,r]),s分钟要洗澡(题目的意思 亚历克斯要洗澡) m分钟总时间,询问你是否有s分钟的间隔完成洗澡的任务。
(这题甚至不用排序,数据给的就是拍好的 li>ri-1)
那只要判断 0到开始第一个事件的时间间隔(a[0].l-0),每个事件的时间间隔(a[i].l;-a[i-1].r).,最后一个时间到结束的时间间隔(m-a[n-1].r)是否满足(>=s)就好了 (数组大小记得看数据,我就开小了 re了一发)。
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N=2e5+10;
int n;
struct in {
int l, r;
};
in a[N];
//{
// if(a.l != b.l) return a.l < b.l;
// return a.r < b.r;
//}
void solve()
{
bool f=0;
int n, s, m;
cin >> n >> s >> m;
for(int i = 1; i <= n; i++)
{
int x, y;
cin >> x >> y;
a[i].l = x;
a[i].r = y;
if(i==1)
{
if(a[1].l >= s)
{
f=1;
}
}
else
{
if(a[i].l - a[i - 1].r >= s)
{
f=1;
}
}
}
if(m-a[n].r>=s) f=1;
if(f)
{
cout << "YES" << endl;
return;
}
else cout << "NO" << endl;
}
int main()
{
ios::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
int t = 1;
cin >> t;
while(t--) {
solve();
}
return 0;
}
题意:
斯拉夫的考试非常难,他需要您的帮助才能通过考试。下面是他正在苦苦思索的问题:
存在一个字符串 s,它由小写英文字母和可能是零个或多个"? "组成。
要求 Slavic 将每个"? "改成小写英文字母,使字符串 t 成为字符串 s的子序列(不一定连续)。
输出任何这样的字符串,如果没有符合条件的字符串存在,则说不可能。
直接暴!力! 遍历 两个字符串进行处理
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
void solve()
{
string x,y;
cin>>x>>y;
int len1=x.size();
int len2=y.size();
int t1,t2;
t1=t2=0;
bool f=0;
for(;;)
{
if(len2==t2)
{
f=1;
break;
}
if(t1>=len1) break;
if(x[t1]!=y[t2]&&x[t1]!='?')
{
//cout<<1<<endl;
t1++;
continue;
}
else
{
if(x[t1]==y[t2])
{
//cout<<2<<endl;
t1++;
t2++;
}
else
{
//cout<<3<<endl;
x[t1++]=y[t2++];
}
}
}
if(!f) cout<<"NO"<<endl;
else
{
for(int i=t1;i<len1;i++)
{
if(x[i]=='?') x[i]='a';
}
cout<<"YES"<<endl;
cout<<x<<endl;
}
}
int main()
{
ios::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
int t=1;
cin>>t;
while(t--)
{
solve();
}
return 0;
}
题意:
艾维在黑板上写下了从l到 r(含)的所有整数。
在一次运算中,她做了以下操作:
- 在黑板上选出两个数字 x和 y,擦掉它们,然后在它们的位置上写下数字 3*x和 [y/3](表示四舍五入到最接近的整数)
要使黑板上的所有数字都等于 0,艾维最少需要进行多少次运算?我们可以证明这总是可能的。
要提前进行前缀处理 不然每次都处理一遍会超时
前缀数组记录可以被3处理几次
然后 l位值的数要特殊处理 (思路是 把最小的数 也就是左端 处理为0 ,这样之后就只要考虑 除3的部分就好了 ( 0乘3都是0 ))
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N=2e5+10;
ll a[N];
void init()
{
for(int i=1;i<=N;i++)
{
int t=i;
while(t)
{
t/=3;
a[i]++;
}
a[i]+=a[i-1];
}
}
void solve()
{
int l,r;
ll sum=0;
cin>>l>>r;
sum+=(a[l]-a[l-1])*2;
sum+=(a[r]-a[l]);
cout<<sum<<endl;
}
int main()
{
ios::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
init();
int t = 1;
cin >> t;
while(t--) {
solve();
}
return 0;
}
感觉f要逆元 但我最近才了解到 不是很会 所以就放弃了 qwq
END