码迷,mamicode.com
首页 > 其他好文 > 详细

Codeforces Round #350 (Div. 2) 题解

时间:2016-05-07 06:58:00      阅读:256      评论:0      收藏:0      [点我收藏+]

标签:

Holidays

#include<bits/stdc++.h>
using namespace std;
#define For(i,n) for(int i=1;i<=n;i++)
#define Fork(i,k,n) for(int i=k;i<=n;i++)
#define Rep(i,n) for(int i=0;i<n;i++)
#define ForD(i,n) for(int i=n;i;i--)
#define ForkD(i,k,n) for(int i=n;i>=k;i--)
#define RepD(i,n) for(int i=n;i>=0;i--)
#define Forp(x) for(int p=Pre[x];p;p=Next[p])
#define Forpiter(x) for(int &p=iter[x];p;p=Next[p])  
#define Lson (o<<1)
#define Rson ((o<<1)+1)
#define MEM(a) memset(a,0,sizeof(a));
#define MEMI(a) memset(a,127,sizeof(a));
#define MEMi(a) memset(a,128,sizeof(a));
#define INF (2139062143)
#define F (100000007)
#define pb push_back
#define mp make_pair 
#define fi first
#define se second
#define vi vector<int> 
#define pi pair<int,int>
#define SI(a) ((a).size())
typedef long long ll;
typedef unsigned long long ull;
ll mul(ll a,ll b){return (a*b)%F;}
ll add(ll a,ll b){return (a+b)%F;}
ll sub(ll a,ll b){return (a-b+llabs(a-b)/F*F+F)%F;}
void upd(ll &a,ll b){a=(a%F+b%F)%F;}
int read()
{
    int x=0,f=1; char ch=getchar();
    while(!isdigit(ch)) {if (ch==‘-‘) f=-1; ch=getchar();}
    while(isdigit(ch)) { x=x*10+ch-‘0‘; ch=getchar();}
    return x*f;
} 
int main()
{
//  freopen("A.in","r",stdin);
//  freopen(".out","w",stdout);

    int n=read(); 
    int t=n/7*2;
    int t1=t+(n%7>=1)+(n%7>=2);
    int t2=t+(n%7>=6);
    cout<<t2<<‘ ‘<<t1<<endl;

    return 0;
}

Game of Robots

#include<bits/stdc++.h>
using namespace std;
#define For(i,n) for(int i=1;i<=n;i++)
#define Fork(i,k,n) for(int i=k;i<=n;i++)
#define Rep(i,n) for(int i=0;i<n;i++)
#define ForD(i,n) for(int i=n;i;i--)
#define ForkD(i,k,n) for(int i=n;i>=k;i--)
#define RepD(i,n) for(int i=n;i>=0;i--)
#define Forp(x) for(int p=Pre[x];p;p=Next[p])
#define Forpiter(x) for(int &p=iter[x];p;p=Next[p])  
#define Lson (o<<1)
#define Rson ((o<<1)+1)
#define MEM(a) memset(a,0,sizeof(a));
#define MEMI(a) memset(a,127,sizeof(a));
#define MEMi(a) memset(a,128,sizeof(a));
#define INF (2139062143)
#define F (100000007)
#define pb push_back
#define mp make_pair 
#define fi first
#define se second
#define vi vector<int> 
#define pi pair<int,int>
#define SI(a) ((a).size())
typedef long long ll;
typedef unsigned long long ull;
ll mul(ll a,ll b){return (a*b)%F;}
ll add(ll a,ll b){return (a+b)%F;}
ll sub(ll a,ll b){return (a-b+llabs(a-b)/F*F+F)%F;}
void upd(ll &a,ll b){a=(a%F+b%F)%F;}
int read()
{
    int x=0,f=1; char ch=getchar();
    while(!isdigit(ch)) {if (ch==‘-‘) f=-1; ch=getchar();}
    while(isdigit(ch)) { x=x*10+ch-‘0‘; ch=getchar();}
    return x*f;
} 
int main()
{
//  freopen("B.in","r",stdin);
//  freopen(".out","w",stdout);

    ll n=read(); ll k=read();

    ll i=1,p=0;
    while(p+i<k) p+=i++;
    int q;
    For(i,k-p-1) read();
    cout<<read()<<endl;

    return 0;
}

Cinema

#include<bits/stdc++.h>
using namespace std;
#define For(i,n) for(int i=1;i<=n;i++)
#define Fork(i,k,n) for(int i=k;i<=n;i++)
#define Rep(i,n) for(int i=0;i<n;i++)
#define ForD(i,n) for(int i=n;i;i--)
#define ForkD(i,k,n) for(int i=n;i>=k;i--)
#define RepD(i,n) for(int i=n;i>=0;i--)
#define Forp(x) for(int p=Pre[x];p;p=Next[p])
#define Forpiter(x) for(int &p=iter[x];p;p=Next[p])  
#define Lson (o<<1)
#define Rson ((o<<1)+1)
#define MEM(a) memset(a,0,sizeof(a));
#define MEMI(a) memset(a,127,sizeof(a));
#define MEMi(a) memset(a,128,sizeof(a));
#define INF (2139062143)
#define F (100000007)
#define pb push_back
#define mp make_pair 
#define fi first
#define se second
#define vi vector<int> 
#define pi pair<int,int>
#define SI(a) ((a).size())
typedef long long ll;
typedef unsigned long long ull;
ll mul(ll a,ll b){return (a*b)%F;}
ll add(ll a,ll b){return (a+b)%F;}
ll sub(ll a,ll b){return (a-b+llabs(a-b)/F*F+F)%F;}
void upd(ll &a,ll b){a=(a%F+b%F)%F;}
int read()
{
    int x=0,f=1; char ch=getchar();
    while(!isdigit(ch)) {if (ch==‘-‘) f=-1; ch=getchar();}
    while(isdigit(ch)) { x=x*10+ch-‘0‘; ch=getchar();}
    return x*f;
} 
#define MAXN (200000+10)
int n,m,a[MAXN],b[MAXN],c[MAXN];
map<int,int> h;
int calc(int i){
    if (h.find(i)!=h.end()) return h[i];return 0;
}
int main()
{
//  freopen("C.in","r",stdin);
//  freopen(".out","w",stdout);
    cin>>n;
    For(i,n) {
        a[i]=read();
        if (h.find(a[i])!=h.end()) h[a[i]]++;
        else h[a[i]]=1;
    }
    cin>>m;
    For(i,m) b[i]=read();
    For(i,m) c[i]=read();
    int p=1;
    For(i,m) {
        if (calc(b[i])>calc(b[p])||(calc(b[i])==calc(b[p])&&calc(c[i])>calc(c[p]))) 
            p=i; 
    }
    cout<<p<<endl;


    return 0;
}

Magic Powder - 1,2

#include<bits/stdc++.h>
using namespace std;
#define For(i,n) for(int i=1;i<=n;i++)
#define Fork(i,k,n) for(int i=k;i<=n;i++)
#define Rep(i,n) for(int i=0;i<n;i++)
#define ForD(i,n) for(int i=n;i;i--)
#define ForkD(i,k,n) for(int i=n;i>=k;i--)
#define RepD(i,n) for(int i=n;i>=0;i--)
#define Forp(x) for(int p=Pre[x];p;p=Next[p])
#define Forpiter(x) for(int &p=iter[x];p;p=Next[p])  
#define Lson (o<<1)
#define Rson ((o<<1)+1)
#define MEM(a) memset(a,0,sizeof(a));
#define MEMI(a) memset(a,127,sizeof(a));
#define MEMi(a) memset(a,128,sizeof(a));
#define INF (2139062143)
#define F (100000007)
#define pb push_back
#define mp make_pair 
#define fi first
#define se second
#define vi vector<int> 
#define pi pair<int,int>
#define SI(a) ((a).size())
typedef long long ll;
typedef unsigned long long ull;
ll mul(ll a,ll b){return (a*b)%F;}
ll add(ll a,ll b){return (a+b)%F;}
ll sub(ll a,ll b){return (a-b+llabs(a-b)/F*F+F)%F;}
void upd(ll &a,ll b){a=(a%F+b%F)%F;}
int read()
{
    int x=0,f=1; char ch=getchar();
    while(!isdigit(ch)) {if (ch==‘-‘) f=-1; ch=getchar();}
    while(isdigit(ch)) { x=x*10+ch-‘0‘; ch=getchar();}
    return x*f;
} 
#define MAXN (100000+10)
int n;
ll k,a[MAXN],b[MAXN];
int check(ll x){
    ll tmp=0;
    For(i,n){
        tmp+=max(0ll,a[i]*x-b[i]);
        if(tmp>k) break;
    }
    return tmp<=k;
}
int main()
{
//  freopen("D.in","r",stdin);
//  freopen(".out","w",stdout);
    n=read(); 
    k=read();
    For(i,n) a[i]=read();
    For(i,n) b[i]=read();

    ll l=0,r=(ll)1e9*2;
    ll ans=0;
    while(l<=r) {
        ll m=(l+r)/2;   
        if (check(m)) l=m+1,ans=m;else r=m-1;
    }
    cout<<ans<<endl;


    return 0;
}

Correct Bracket Sequence Editor

#include<bits/stdc++.h>
using namespace std;
#define For(i,n) for(int i=1;i<=n;i++)
#define Fork(i,k,n) for(int i=k;i<=n;i++)
#define Rep(i,n) for(int i=0;i<n;i++)
#define ForD(i,n) for(int i=n;i;i--)
#define ForkD(i,k,n) for(int i=n;i>=k;i--)
#define RepD(i,n) for(int i=n;i>=0;i--)
#define Forp(x) for(int p=Pre[x];p;p=Next[p])
#define Forpiter(x) for(int &p=iter[x];p;p=Next[p])  
#define Lson (o<<1)
#define Rson ((o<<1)+1)
#define MEM(a) memset(a,0,sizeof(a));
#define MEMI(a) memset(a,127,sizeof(a));
#define MEMi(a) memset(a,128,sizeof(a));
#define INF (2139062143)
#define F (100000007)
#define pb push_back
#define mp make_pair 
#define fi first
#define se second
#define vi vector<int> 
#define pi pair<int,int>
#define SI(a) ((a).size())
typedef long long ll;
typedef unsigned long long ull;
ll mul(ll a,ll b){return (a*b)%F;}
ll add(ll a,ll b){return (a+b)%F;}
ll sub(ll a,ll b){return (a-b+llabs(a-b)/F*F+F)%F;}
void upd(ll &a,ll b){a=(a%F+b%F)%F;}
int read()
{
    int x=0,f=1; char ch=getchar();
    while(!isdigit(ch)) {if (ch==‘-‘) f=-1; ch=getchar();}
    while(isdigit(ch)) { x=x*10+ch-‘0‘; ch=getchar();}
    return x*f;
} 
#define MAXN (500000+10)
struct link  
{  
    int pre,next;  
}l[MAXN];  
void del(int x)  
{  
    l[l[x].pre].next=l[x].next;  
    l[l[x].next].pre=l[x].pre;    
}  
void del(int x,int y)  
{  
    if (x>y) swap(x,y);
    l[l[x].pre].next=l[y].next;  
    l[l[y].next].pre=l[x].pre;    
}  

int n,m,p;
char s[MAXN],oper[MAXN];
int st[MAXN],siz=0;
int to[MAXN];
int main()
{
//  freopen("E.in","r",stdin);
//  freopen(".out","w",stdout);

    cin>>n>>m>>p>>(s+1);
    for (int i=1;i<=n;i++) {l[i-1].next=i;l[i].pre=i-1;} l[n].next=0;  

    For(i,n) {
        if (s[i]==‘(‘) st[++siz]=i;
        else {
            to[i]=st[siz];
            to[st[siz]]=i;
            siz--;
        }
    }
    cin>>oper;
    Rep(i,m) {
        if (oper[i]==‘R‘) {
            p=l[p].next;
        } 
        else if (oper[i]==‘L‘) {
            p=l[p].pre;
        } 
        else {
            del(p,to[p]);
            if (l[max(p,to[p])].next) p=l[max(p,to[p])].next; else p=l[min(p,to[p])].pre;
        } 

    }   
    for(int i=l[0].next;i;i=l[i].next) cout<<s[i];


    return 0;
}

Restore a Number

特判0

#include<bits/stdc++.h>
using namespace std;
#define For(i,n) for(int i=1;i<=n;i++)
#define Fork(i,k,n) for(int i=k;i<=n;i++)
#define Rep(i,n) for(int i=0;i<n;i++)
#define ForD(i,n) for(int i=n;i;i--)
#define ForkD(i,k,n) for(int i=n;i>=k;i--)
#define RepD(i,n) for(int i=n;i>=0;i--)
#define Forp(x) for(int p=Pre[x];p;p=Next[p])
#define Forpiter(x) for(int &p=iter[x];p;p=Next[p])  
#define Lson (o<<1)
#define Rson ((o<<1)+1)
#define MEM(a) memset(a,0,sizeof(a));
#define MEMI(a) memset(a,127,sizeof(a));
#define MEMi(a) memset(a,128,sizeof(a));
#define INF (2139062143)
#define F (100000007)
#define pb push_back
#define mp make_pair 
#define fi first
#define se second
#define vi vector<int> 
#define pi pair<int,int>
#define SI(a) ((a).size())
typedef long long ll;
typedef unsigned long long ull;
ll mul(ll a,ll b){return (a*b)%F;}
ll add(ll a,ll b){return (a+b)%F;}
ll sub(ll a,ll b){return (a-b+llabs(a-b)/F*F+F)%F;}
void upd(ll &a,ll b){a=(a%F+b%F)%F;}
int read()
{
    int x=0,f=1; char ch=getchar();
    while(!isdigit(ch)) {if (ch==‘-‘) f=-1; ch=getchar();}
    while(isdigit(ch)) { x=x*10+ch-‘0‘; ch=getchar();}
    return x*f;
} 

#define MAXN (1000000+10)
char s1[MAXN],s2[MAXN];
int a[10]={0},b[10]={0};
int c[10]={0},n,m;
int calc(int len) {
    int p=0;
    while(len) {len/=10;++p;    }
    return p;
}
bool check(int len) {
    MEM(c)
    int p=0;
    int len2=len;
    while(len) {c[len%10]++;len/=10;++p;    }
    if (len2!=n-p) return 0;
    int flag=s2[1]!=‘0‘;
    Rep(i,10) {
        if (a[i]<b[i]+c[i]) return 0;
        else if (a[i]>b[i]+c[i]) flag=1;
    }
    return flag;
}
char tmp[MAXN],len=0;
string s[11];
int cmp(string x,string y){
    if (x=="") return 1;
    string p1=x+y,p2=y+x;
    return p1<p2;
}
vector<string> v;
int main()
{
//  freopen("F.in","r",stdin);
//  freopen(".out","w",stdout);
    cin>>(s1+1)>>(s2+1);
    n=strlen(s1+1);
    For(i,n) a[s1[i]-‘0‘]++;
    m=strlen(s2+1);
    For(i,m) b[s2[i]-‘0‘]++;
    if (string(s1+1)=="01"||string(s1+1)=="10") {
        cout<<"0"<<endl; return 0;
    }

    {
        int l=0,r=1000000,ans=1;
        while(l<=r) {
            int m=(l+r)/2;
            if (m+calc(m)<=n) ans=m,r=m-1;else l=m+1; 
        }
        check(ans);
    }

    int len=0;
    while(!check(len)) ++len;

    Rep(i,10) a[i]-=b[i]+c[i]; 

    if (s2[1]!=‘0‘) { 
        strcpy(tmp,s2+1); len=m;
        Rep(i,10) Rep(k,a[i]) tmp[len++]=‘0‘+i;
        tmp[len]=0;
        v.pb((string)tmp);
    }
    For(i,9) if (a[i]!=0) {
        len=0;
        tmp[len++]=‘0‘+i;
        --a[i];
        s[10].assign(s2+1);
        Rep(i,10) {
            if (s2[1]-‘0‘==i) {
                if (cmp(s[10],string(1,‘0‘+i))) {
                    strcpy(tmp+len,s2+1);len+=m;
                    Rep(k,a[i]) tmp[len++]=‘0‘+i;
                }               
                else {
                    Rep(k,a[i]) tmp[len++]=‘0‘+i;
                    strcpy(tmp+len,s2+1);len+=m;
                }
            }
            else Rep(k,a[i]) tmp[len++]=‘0‘+i;

        }
            tmp[len]=0;
        v.pb((string)tmp);
        ++a[i]; 
        break;
    } 
    sort(v.begin(),v.end());
    cout<<v[0]<<endl;

    return 0;
}

Codeforces Round #350 (Div. 2) 题解

标签:

原文地址:http://blog.csdn.net/nike0good/article/details/51335648

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!