Educational Codeforces Round 72 (Rated for Div. 2)

链接:http://codeforces.com/contest/1217

A. Creating a Character

#include<iostream>
#include<algorithm>
#include<cstdio>
#include<vector>
#include<stack> 
#include<cstring>
#include<map>
#include<queue> 
#include<cmath>
#include<set> 
#include<deque>
#define INF 0x3f3f3f3f
#define lowbit(a) ((a)&-(a))
#define speed std::ios::sync_with_stdio(false),cin.tie(NULL),cout.tie(NULL)
using namespace std;
typedef long long ll;
queue<ll> q;
stack<ll> s;
deque<ll> deq;
priority_queue<ll> pq;  
const ll maxn = 200005;
ll n,m,l,r,k;
ll ans=0;
ll a[maxn]; 
int main()
{
 ll T;
    cin>>T;
    while (T--){
        ll ans=0;
        cin>>n>>m>>k;
        if(m+k>=n){
            ll i,ans;
            i=0;
            ans=0;
            while(2*i<n-m+k){ //因为一次改变要2个value 
             i++;
   }
            cout<<i<<endl;
        }
        else
            cout<<k+1<<endl; 
    }
 return 0;
} 

B. Zmei Gorynich
数据也太水了吧

#include<iostream>
#include<algorithm>
#include<cstdio>
#include<vector>
#include<stack> 
#include<cstring>
#include<map>
#include<queue> 
#include<cmath>
#include<set> 
#include<deque>
#define INF 0x3f3f3f3f
#define lowbit(a) ((a)&-(a))
#define speed std::ios::sync_with_stdio(false),cin.tie(NULL),cout.tie(NULL)
using namespace std;
typedef long long ll;
queue<ll> q;
stack<ll> s;
deque<ll> deq;
priority_queue<ll> pq;  
const ll maxn = 200005;
ll n,m;
ll a[maxn]; 
struct node{
 ll l,r;
}p[maxn];
bool cmp(node a,node b)
{
 return a.l-a.r>b.l-b.r;
}
int main()
{
 ll T;
 cin>>T;
 while(T--){
  ll ans=1;
  cin>>n>>m;
  ll maxx=-INF;
  for(ll i=1;i<=n;i++){
   cin>>p[i].l>>p[i].r;
   maxx=max(maxx,p[i].l);
  } 
  sort(p+1,p+1+n,cmp);
  if(p[1].l<=p[1].r&&maxx<m){ //看看能不能一刀秒
   cout<<"-1\n";
   continue;
  }
  else if(maxx>=m){ //可以的话
   cout<<"1\n";
   continue;
  }
  m-=maxx;
  if(m%(p[1].l-p[1].r)==0){
   ans+=m/(p[1].l-p[1].r);
  }
  else{
   ans+=m/(p[1].l-p[1].r)+1;
  }
  cout<<ans<<endl;
 }
} 

C. The Number Of Good Substrings

#include<iostream>
#include<algorithm>
#include<cstdio>
#include<vector>
#include<stack> 
#include<cstring>
#include<map>
#include<queue> 
#include<cmath>
#include<set> 
#include<deque>
#define INF 0x3f3f3f3f
#define lowbit(a) ((a)&-(a))
#define speed std::ios::sync_with_stdio(false),cin.tie(NULL),cout.tie(NULL)
using namespace std;
typedef long long ll;
queue<ll> q;
stack<ll> s;
deque<ll> deq;
priority_queue<ll> pq;  
const ll maxn = 200005;
ll n,m,l,r;
ll ans=0;
ll a[maxn]; 
int main()
{
 ll T;
 cin>>T;
 while(T--){
  string str;
  cin>>str;
  ans=0;
  ll num0=0;
  for(ll i=0;i<str.size();i++){
   if(str[i]=='0')
    num0++;
   else{
    ll res=0;
    for(ll j=i;j<str.size()&&res<=num0+(j-i+1);j++){
     res=2*res+str[j]-'0'; //res为从i开始的1的计算 
     if(res>=(j-i+1)&&res<=(num0+j-i+1)){ 
      //cout<<res<<endl;
      ans++;
     }//只要res>=二进制下区间长度len并且res<=len+num_0,则会产生答案,因为前导0可以匹配,但如果这样不行,直接break 
     else //因为区间是以1个单位增加的,但二进制的值至少以二倍增加的 
      break;
    }
    num0=0;
   }
  }
  cout<<ans<<endl;
 }
} 

D. Coloring Edges(拓扑排序找环)

#include<iostream>
#include<algorithm>
#include<cstdio>
#include<vector>
#include<stack> 
#include<cstring>
#include<map>
#include<queue> 
#include<cmath>
#include<set> 
#include<deque>
#define INF 0x3f3f3f3f
#define lowbit(a) ((a)&-(a))
#define speed std::ios::sync_with_stdio(false),cin.tie(NULL),cout.tie(NULL)
using namespace std;
typedef long long ll;
queue<ll> q;
stack<ll> s;
deque<ll> deq;
priority_queue<ll> pq;  
const ll maxn = 200005;
ll n,m,l,r;
ll ans=0;
pair<ll,ll> a[maxn];
vector<ll> v[maxn];
ll d[maxn]; //指向他的 
bool f[maxn];
int main()
{
 cin>>n>>m;
 ll flag=0;
 for(ll i=1;i<=m;i++){
  cin>>a[i].first>>a[i].second;
  v[a[i].first].push_back(a[i].second);
  d[a[i].second]++;
 }
 for(ll i=1;i<=n;i++){ //拓扑排序求环 
  ll mn=0;
  for(ll j=1;j<=n;j++){
   if(d[j]==0&&f[j]==0)
    mn=j;
  }
  f[mn]=1;
  if(mn==0){ 
   flag=1;
   break;
  }
  for(ll j=0;j<v[mn].size();j++){
   d[v[mn][j]]--;
  }
 }
 if(flag==0){ //无环 
  cout<<1<<endl;
  for(ll i=1;i<=m;i++){
   cout<<"1 ";
  }
 } 
 else{ //有环 
  cout<<2<<endl;
  for(ll i=1;i<=m;i++){
   if(a[i].first<a[i].second) cout<<"1 ";
   else cout<<"2 ";
  }
 }
 return 0;
}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值