Dashboard - Codeforces Round #704 (Div. 2) - Codeforces

Dashboard - Codeforces Round #704 (Div. 2) - Codeforces

1.Problem - A - Codeforces

挺简单,但是为了记录一下wal一发的痛苦

#include<bits/stdc++.h>
using namespace std;
#define IOS ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define fel(i,x,y) for(int i=x;i<=y;i++)
#define fhl(i,x,y) for(int i=x;i>=y;i--)
#define inf 0x3fffffff
#define ll long long
#define pb push_back
#define endl "\n"
ll p,a,b,c;
void slove(){
cin>>p>>a>>b>>c;
if(p%a==0||p%b==0||p%c==0){
cout<<0<<endl;
return;
}
ll t1=(a-p%a);
ll t2=(a-p%b);
ll t3=(c-p%c);
cout<<min({t1,t2,t3})<<endl;
}
int main(){
int t;
cin>>t;
while(t--){
slove();
}
return 0;
}

2.Problem - B - Codeforces

这个题写的时候乱搞过去了,正解其实也就是这个,就考虑先把目前最大的放到底部。这样就可以产生最大值。大部分题解也就是说使字典序尽量大,所以就是使当前最大的尽量在前面。

最后用一个集合记录一下此时的最大值是什么就好了。

#include<bits/stdc++.h>
using namespace std;
#define IOS ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define fel(i,x,y) for(int i=x;i<=y;i++)
#define fhl(i,x,y) for(int i=x;i>=y;i--)
#define inf 0x3fffffff
#define ll long long
#define pb push_back
#define endl "\n"
const int N=1e5+100;
int n;
int a[N];
//贪心肯定就是尽量使比较大的在下面,所以我每次遍历到当前最大值,讲所有元素放到栈里面
//所有元素是不一样的,那就是个全排列,那最大值就很好找了
void slove(){
cin>>n;
set<int>jh;
fel(i,1,n){
cin>>a[i];
jh.insert(a[i]);
}
stack<int>s;
for(int i=n;i>=1;i--){
auto p=jh.end();
p--;
int mx=*p;
int j=i;
while(a[j]!=mx&&j>=1){
s.push(a[j]);
j--;
}
if(a[j]==mx&&mx!=0){
s.push(a[j]);
}
i=j;
while(!s.empty()){
cout<<s.top()<<" ";
jh.erase(jh.find(s.top()));
s.pop();
}
}
cout<<endl;
}
int main(){
int t;
cin>>t;
while(t--){
slove();
}
return 0;
}

3.Problem - C - Codeforces

这个题就记录每个字母最早出现点,和最晚出现点。但是求最早出现点的得从最前面开始,最晚出现点得从最后面开始,为什么呢?因为这样才能保证字符串s的子序列是肯定可以形成t序列的。

比如说abbbab 和 abab,如果你求最晚出现点从前面开始遍历那t的第二个b就会占用s中的最后一个b,那最后一个b就无法找到位置了。

#include<bits/stdc++.h>
using namespace std;
#define IOS ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define fel(i,x,y) for(int i=x;i<=y;i++)
#define fhl(i,x,y) for(int i=x;i>=y;i--)
#define inf 0x3fffffff
#define ll long long
#define pb push_back
#define endl "\n"
const int N=2e5+100;
int n,m;
string s,t;
//就是先从千米那匹配每个t字符出现的最早位置
//再从后面匹配每个字符可以出现的最晚位置
//然后求相邻两个字符的最后出现位置减去最先出现位置的最大值
int f[N],se[N];
int main(){
cin>>n>>m;
cin>>s;
cin>>t;
int step=0;
for(int i=0;i<n&&step<m;i++){
if(s[i]==t[step]) f[step++]=i;
}
step=m-1;
for(int i=n-1;i>=0&&step>=0;i--){
if(s[i]==t[step]) se[step--]=i;
}
int ans=0;
for(int i=0;i<m-1;i++){
ans=max(ans,se[i+1]-f[i]);
}
cout<<ans<<endl;
}

4.Problem - D - Codeforces

这个题wa了n发,主要还是考虑的太片面了,两种可以和起来讨论的情况被我疯狂分类讨论。这个题只要想到两个1是错位并且中间数全是相同的就可以产生pos1-pos2个1就好了。然后需要保证没有前导0.所以第一位为1.我们令s的第二位为1。第k+2位为0,t的第二位为0,第k+2位为1,中间全是相同的,这样他们相减就可以产生k个1.其他的随便排就可以了。

#include<bits/stdc++.h>
using namespace std;
#define IOS ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define fel(i,x,y) for(int i=x;i<=y;i++)
#define fhl(i,x,y) for(int i=x;i>=y;i--)
#define inf 0x3fffffff
#define ll long long
#define pb push_back
#define endl "\n"
//感觉就是0就是我可以产生的1的个数。
//所以如果k比0多,那k比0多就没有希望了
//发现一个问题
//就是1也是可以产生0的,比如说110-011答案就是011,所以说并不是0才可以变成1
//所以能产生的1的最大值是a-1+b-2
//确实是想复杂了,你只要中间全是相同的就ok了,这样也是相减可以产生i-j个1
int a,b,k;
int t1,t2;
void slove(int n){
for(int i=1;i<=n;i++){
if(t1){
cout<<0;
t1--;
}
else if(t2){
cout<<1;
t2--;
}
}
}
int main(){
cin>>a>>b>>k;
if(k==0){
cout<<"YES"<<endl;//k等于0肯定ok
string s;
for(int i=1;i<=b;i++) s+="1";
for(int j=1;j<=a;j++) s+="0";
cout<<s<<endl;
cout<<s<<endl;
return 0;
}
if(k>a+b-2||(b==1&&k)||(a==0&&k)){
cout<<"NO"<<endl;
return 0;
}
cout<<"YES"<<endl;
a-=1,b-=2;
cout<<11;
//然后就考虑输出1-0中间隔着k-1个数后输出一个0
t1=a,t2=b;
slove(k-1);
cout<<0;
slove(a+b-k+1);
cout<<endl;

t1=a,t2=b;
cout<<10;
slove(k-1);
cout<<1;
slove(a+b-k+1);
return 0;
}

 

5.关于for循环的一些细节

#include<bits/stdc++.h>
using namespace std;
#define IOS ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define fel(i,x,y) for(int i=x;i<=y;i++)
#define fhl(i,x,y) for(int i=x;i>=y;i--)
#define inf 0x3fffffff
#define ll long long
#define pb push_back
#define endl "\n"
const int N=1e5+100;
int main(){
for(int i=1;i<=10;i++){
       //这个for循环时一个死循环
       //for是先进行循环出来之后对现在的i++;
       //这个循环每次进去都会把i-1出来之后又加一,所以是个死循环
       //i只始终不变
int j=i;
cout<<j<<endl;
j--;
i=j;
cout<<i<<endl;
system("pause");
}
}
 
posted @ 2022-07-30 17:04  silky__player  阅读(92)  评论(0)    收藏  举报