Atcoder Regular Contest 103 (待補全)
阿新 • • 發佈:2019-01-23
C
搞個桶暴力即可,注意要求兩種不同的數字,需要特判一下
D
給定平面上的個點,求個序列,每個序列表示上下左右,起點是遠點,然後從原點按照N個序列走,權值是D序列(順序對應),要求恰好走到這N個點,求這樣的序列和D序列
待補
E
You are given a string s of length n. Does a tree with n vertices that satisfies the following conditions exist?
The vertices are numbered 1,2,…,n.
The edges are numbered 1,2,…,n−1, and Edge i connects Vertex ui and vi.
If the i-th character in s is 1, we can have a connected component of size i by removing one edge from the tree.
If the i-th character in s is 0, we cannot have a connected component of size i by removing any one edge from the tree.
If such a tree exists, construct one such tree.
題目要構造一顆樹,滿足上面兩個條件(即存在大小是i的子樹,且不存在大小為j的子樹,其中a[i]=1,a[j]=0,a陣列是給定的)
在1~n-1範圍內串要是對稱的(因為x和n-x的聯通大小是並存的),且a[1]=1 a[n]=0
其餘的向下面這樣連線:
#include<bits/stdc++.h>
#define debug cout<<"debug "<<++debug_num<<" :"
#define pb push_back
#define mp make_pair
using namespace std;
typedef long long ll;
typedef pair<int,int> PII;
int debug_num=0;
string s;
int n;
const int maxn=1e5+10;
int a[maxn];
bool check(int x)
{
for(int i=1;i<=x;++i){
if(a[i]!=a[n-i]) return false;
}
if(a[1]!=1 || a[n]!=0) return false;
return true;
}
int main()
{
//freopen("in.txt","r",stdin);
ios::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
cin>>s;
n=s.size();
//cout<<s<<endl;
for(int i=0;i<n;++i){
a[i+1]=s[i]-'0';
//cout<<a[i+1]<<endl;
}
if(!check(n/2)){
cout<<-1<<endl;
}
else{
int tp1=1;
int tp2;
for(int i=2;i<=n;++i){
if(a[i]==1){
tp2=i;
cout<<tp2<<" "<<tp1<<endl;
for(int i=tp1+1;i<tp2;++i){
cout<<tp2<<" "<<i<<endl;
}
tp1=tp2;
}
}
cout<<n<<" "<<n-1<<endl;
}
return 0;
}
F
待補