本文主要是介绍Codeforces Round #777 (Div. 2) 部分题解,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
前言
最近事情比较多,基本上没有时间参加,只能找时间vp一下
一、A. Madoka and Math Dad
一眼题,位数优先大于数字,相邻的数字不能相同,3可以分成21,111则不满足
#include<bits/stdc++.h>using namespace std;const int inf =0x3f3f3f3f;#define IOS ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);#define in freopen("in.txt","r",stdin)#define out freopen("out.txt","w",stdout)#define ms(x,a) memset(x,a,sizeof(x))#define ll long long#define pb push_back#define pr pair<int,int>#define debug printf("%d %s\n",__LINE__,__FUNCTION__)#define rep(i, a, n) for(int i=a; i<=n; i++)#define rg register int//卡常#define ojconst int mod=1e9+7;const int maxn=1e6+10;const int maxe=1e6+5;int n,m,a[maxn],siz[maxn];vector<int> g[maxn];void solve(){scanf("%d",&n);m=n%3;int t=n/3;if(m==0){for(int i=1;i<=t;i++){printf("21");}}else if(m==1){printf("1");for(int i=1;i<=t;i++){printf("21");}}else{for(int i=1;i<=t;i++){printf("21");}printf("2");}printf("\n");}int main(){int T;scanf("%d",&T);while(T--){solve();}return 0;}/*#ifndef oj in;out;#endif*/
二、B. Madoka and the Elegant Gift
意思是每一个黑块组合起来都是极大的,进一步分析也就是每一块就是矩形,要求必须要正正方方。
即不能有一个凸出块,于是只要每次考虑2×2的块就好了,如果有3个黑那就是必有凸出,等于遍历一遍O(n*m);
#include<bits/stdc++.h>
using namespace std;
const int inf =0x3f3f3f3f;
#define IOS ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define in freopen("in.txt","r",stdin)
#define out freopen("out.txt","w",stdout)
#define ms(x,a) memset(x,a,sizeof(x))
#define ll long long
#define pb push_back
#define pr pair<int,int>
#define debug printf("%d %s\n",__LINE__,__FUNCTION__)
#define rep(i, a, n) for(int i=a; i<=n; i++)
#define rg register int//卡常
#define oj
const int mod=1e9+7;
const int maxn=100+10;
const int maxe=1e6+5;int n,m,a[maxn];
char mp[maxn][maxn];
bool vis[maxn][maxn];
int dir[4][2]={{0,0},{0,1},{-1,0},{-1,1}};
bool legal(int x,int y){return x>=0 &&y>=0 && x<n && y<n;
}
bool check()
{for(int i=1;i<n;i++){for(int j=0;j<m-1;j++){int black=0,white=0;for(int k=0;k<4;k++){int u=i+dir[k][0],v=j+dir[k][1];if(mp[u][v]=='0'){white++;}else{black++;}}if(black==3) return false;}}return true;
}
void solve()
{scanf("%d %d",&n,&m);for(int i=0;i<n;i++){scanf("%s",mp[i]);}if(check()){printf("YES\n");}else{printf("NO\n");}
}
int main()
{int T;scanf("%d",&T);while(T--){solve();}return 0;
}
/*#ifndef oj in;out;#endif
*/
三、C. Madoka and Childish Pranks
#include<bits/stdc++.h>
using namespace std;
const int inf =0x3f3f3f3f;
#define IOS ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define in freopen("in.txt","r",stdin)
#define out freopen("out.txt","w",stdout)
#define ms(x,a) memset(x,a,sizeof(x))
#define ll long long
#define pb push_back
#define pr pair<int,int>
#define debug printf("%d %s\n",__LINE__,__FUNCTION__)
#define rep(i, a, n) for(int i=a; i<=n; i++)
#define rg register int//卡常
#define oj
const int mod=1e9+7;
const int maxn=100+10;
const int maxe=1e6+5;int n,m,a[maxn];
int mp[maxn][maxn];
int board[maxn][maxn];
int dir[4][2]={{0,0},{0,1},{-1,0},{-1,1}};
int tot=0;
vector<pr> l,r;
void check()
{for(int i=n;i>=1;i--){for(int j=m;j>=1;j--){if(mp[i][j]==0) continue;if(i>1 && mp[i][j]==1){l.pb({i-1,j});r.pb({i,j});}else if(j>1 && mp[i][j]==1){l.pb({i,j-1});r.pb({i,j});}}}
}
void solve()
{scanf("%d %d",&n,&m);l.clear();r.clear();char s[maxn];for(int i=1;i<=n;i++){scanf("%s",s+1);for(int j=1;j<=m;j++){mp[i][j]=s[j]-'0';}}//for(int i=1;i<=n;i++){// for(int j=1;j<=m;j++){// cout<<mp[i][j]<<' ';// }// cout<<endl;//}if(mp[1][1]==1) {printf("-1\n");return;}check();printf("%d\n",l.size());for(int i=0;i<l.size();i++){printf("%d %d %d %d\n",l[i].first,l[i].second,r[i].first,r[i].second);}
}
int main()
{//out;int T;scanf("%d",&T);while(T--){solve();}return 0;
}
/*#ifndef oj in;out;#endif
*/
四、D.Madoka and the Best School in Russia
wa的多了…就知道哪里不对了,流豆黄汗
#include<bits/stdc++.h>
using namespace std;
typedef pair<int,int> pr;
const int inf =0x3f3f3f3f;
#define IOS ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define in freopen("in.txt","r",stdin)
#define out freopen("out.txt","w",stdout)
#define ms(x,a) memset(x,a,sizeof(x))
#define ll long long
#define pb push_back
#define pr pair<int,int>
#define debug printf("%d %s\n",__LINE__,__FUNCTION__)
#define rep(i, a, n) for(int i=a; i<n; i++)
#define rg register int//卡常
#define ONLINE_JUDGE
const int mod=1e9+7;
const int maxn=2e6+10;
const int maxe=1e6+5;int n,m,a[maxn];
int tot;
int prim[maxn];
void getprim()
{tot=0;for(int i=2;i<maxn;i++){if(!prim[i]) prim[++tot]=i;for(int j=1;j<=tot && prim[j]*i<maxn;j++){prim[prim[j]*i]=1;if(i%prim[j]==0) break;}}
}
bool isprime(int x)
{for(int i=2;i*i<=x;i++){if(x%i==0) return false;}return true;
}
void solve()
{scanf("%d %d",&n,&m);tot=0;while(n%m==0){tot++;n/=m;}if(tot==0 || tot==1){printf("NO\n");return;}if(isprime(n)){if(isprime(m)){printf("NO\n");return;}else{if(tot==2){printf("NO\n");return;}else if(tot==3){for(int i=2;i*i<=m;i++){if(m%i==0){int k=m/i;if(k*n%m!=0 || n*i%m!=0){printf("YES\n");return;}}}printf("NO\n");return;}else{printf("YES\n");return;}}}else{printf("YES\n");return;}
}
int main()
{int t=1;scanf("%d",&t);while(t--){solve();}return 0;
}
五、E.Madoka and the Sixth-graders
显然考虑到几个座位之间形成一个环
进一步考虑用倍增的方法来做
唉,当时没想到是倍增来降下去复杂度
然后根据当前的最大号的同学,显然是补进来的
每次补进来的位置时固定的
然后就可以得到轮数,根据建立的表得出最初始的位置上固定的人,也就是最后都留在位置上的同学位置
再根据从小到大安置
并将前n个没有出现的同学按次序放入空位,OK!
#include<bits/stdc++.h>
using namespace std;
typedef pair<int,int> pr;
const int inf =0x3f3f3f3f;
#define IOS ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define in freopen("in.txt","r",stdin)
#define out freopen("out.txt","w",stdout)
#define ms(x,a) memset(x,a,sizeof(x))
#define ll long long
#define pb push_back
#define pr pair<int,int>
#define debug printf("%d %s\n",__LINE__,__FUNCTION__)
#define rep(i, a, n) for(int i=a; i<n; i++)
#define rg register int//卡常
#define ONLINE_JUDGE
const int mod=1e9+7;
const int maxn=1e5+10;
const int maxe=1e6+5;int n,m;ll a[maxn],b[maxn];
int tot;
int to[maxn][30];//倍增
int desk[maxn];
void solve()
{scanf("%d",&n);for(int i=1;i<=n;i++){scanf("%lld",&a[i]);to[i][0]=a[i];}for(int i=1;i<=n;i++){scanf("%lld",&b[i]);}for(int i=1;i<30;i++){for(int j=1;j<=n;j++){to[j][i]=to[to[j][i-1]][i-1];}}//这>...怎么感觉有种函数式编程的感觉,学到了新的去重方法int k=(*max_element(b+1,b+1+n)-n)/(n-unordered_set<int>(a+1,a+1+n).size());for(int i=1;i<=n;i++) desk[i]=i;for(int i=0;i<30;i++){if(k&(1<<i)){for(int j=1;j<=n;j++){desk[j]=to[desk[j]][i];}}}set<int> st;for(int i=1;i<=n;i++) st.insert(i);vector<int> ans(n+1,0);vector<bool> vis(n+1,false);for(int i=1;i<=n;i++){if(vis[desk[i]]) continue;ans[i]=b[desk[i]];vis[desk[i]]=true;st.erase(b[desk[i]]);}for(int i=1;i<=n;i++){if(ans[i]) continue;auto it=st.lower_bound(b[desk[i]]);ans[i]=*it;st.erase(it);}for(int i=1;i<=n;i++){printf("%d ",ans[i]);}
}
int main()
{int t=1;//scanf("%d",&t);while(t--){solve();}return 0;
}
六、F.Madoka and Laziness
F题大概率写不出来…
这篇关于Codeforces Round #777 (Div. 2) 部分题解的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!