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

Codeforces Global Round 3

时间:2019-06-02 12:55:00      阅读:128      评论:0      收藏:0      [点我收藏+]

标签:cin   style   min   isp   put   src   std   clr   hid   

A. Another One Bites The Dust

有三种序列 a b ab   给出各数量

求连成的最长长度 (相邻两个字符不同)

签到水题:

技术图片
#include<bits/stdc++.h>
using namespace std;
//input by bxd
#define rep(i,a,b) for(int i=(a);i<=(b);i++)
#define RI(n) scanf("%d",&(n))
#define RII(n,m) scanf("%d%d",&n,&m)
#define RIII(n,m,k) scanf("%d%d%d",&n,&m,&k)
#define RS(s) scanf("%s",s);
#define ll long long
#define REP(i,N)  for(int i=0;i<(N);i++)
#define CLR(A,v)  memset(A,v,sizeof A)
//////////////////////////////////
#define inf 2147483647
const int N=1e6;
const int M=1e6;

int main()
{
    ll a,b,c;
    cin>>a>>b>>c;

    ll ans=2*c;
    ans+=min(a,b)*2;
    if(a!=b)ans+=1;
    cout<<ans;

    return 0;
}
View Code

 

 

B. Born This Way*

题意:有两条航线  航线1 :a-b  航线2:b-c

有人要从a-c  

给出各个航线的起始时间  和两个t(表示两种航线的航线时间   航线相同的航行时间相同)

你可以取消k次   让该人到达时间最晚(不能到达输出-1)

 

挺好的一题, 题目给出的时间为递增  显然是二分

但还是想错了两次  在这题浪费了太多时间QAQ 

可以枚举航线1删除的个数  t   显然删除的方法只有一种 那就是从1开始删除t个   然后下面二分查找就解决了。。。

技术图片
#include<bits/stdc++.h>
using namespace std;
//input by bxd
#define rep(i,a,b) for(int i=(a);i<=(b);i++)
#define RI(n) scanf("%d",&(n))
#define RII(n,m) scanf("%d%d",&n,&m)
#define RIII(n,m,k) scanf("%d%d%d",&n,&m,&k)
#define RS(s) scanf("%s",s);
#define ll long long
#define REP(i,N)  for(int i=0;i<(N);i++)
#define CLR(A,v)  memset(A,v,sizeof A)
//////////////////////////////////
#define inf 2147483647
const int N=1e6;
const int M=1e6;

ll a[N],b[N],t1,t2,k,n,m;

int main()
{
    cin>>n>>m>>t1>>t2>>k;

    rep(i,1,n)scanf("%lld",&a[i]),a[i]+=t1;
    rep(i,1,m)scanf("%lld",&b[i]);

    if(n<=k||m<=k){printf("-1");return 0;}

    ll ans=0;
    rep(i,0,k)
    {
        int pos=lower_bound(b+1,b+1+m,a[1+i])-b;
        pos+=(k-i);
        if(pos>m){printf("-1");return 0;}
        ans=max(ans,b[pos]+t2);
    }
    cout<<ans;

    return 0;
}
View Code

 

C. Crazy Diamond

给定一个1-n的乱序序列  n为偶数

要求通过操作  使得有序化

输出操作的过程(不要求操作最小化)

技术图片

其实思路很好想  就是一个贪心  中间两个是最难放的  从中间开始即可

编码浪费了太多时间。。。。

 

技术图片
#include<bits/stdc++.h>
using namespace std;
//input by bxd
#define rep(i,a,b) for(int i=(a);i<=(b);i++)
#define RI(n) scanf("%d",&(n))
#define RII(n,m) scanf("%d%d",&n,&m)
#define RIII(n,m,k) scanf("%d%d%d",&n,&m,&k)
#define RS(s) scanf("%s",s);
#define ll long long
#define REP(i,N)  for(int i=0;i<(N);i++)
#define CLR(A,v)  memset(A,v,sizeof A)
//////////////////////////////////
#define inf 2147483647
const int N=1e6;
const int M=1e6;

int a[N],L,R,n,cnt,ans[N][2],pos[N];

void change(int x,int y)
{
    ans[++cnt][0]=x;
    ans[cnt][1]=y;
    swap(a[x],a[y]);
    swap(pos[ a[x] ],pos[ a[y] ]);
}
int main()
{
    RI(n);
    rep(i,1,n)RI(a[i]),pos[ a[i] ]=i;
    L=n/2;R=L+1;
    int key=n/2;
    rep(i,1,key)
    {
        if(pos[L]!=L)
        {
            if(abs(pos[L]-L)>=key)
            change(pos[L],L);
            else
            {
                if(abs(pos[L]-1)>=key)
                change(pos[L],1);
                if(abs(pos[L]-n)>=key)
                change(pos[L],n);
                if(abs(pos[L]-L)>=key)
                change(pos[L],L);
            }
        }
        if(pos[R]!=R)
        {
            if(abs(pos[R]-R)>=key)
            change(pos[R],R);
            else
            {
                if(abs(pos[R]-n)>=key)
                change(pos[R],n);
                if(abs(pos[R]-1)>=key)
                change(pos[R],1);
                if(abs(pos[R]-R)>=key)
                change(pos[R],R);
            }
        }
        L--;R++;
    }
    cout<<cnt<<endl;
    rep(i,1,cnt) printf("%d %d\n",ans[i][0],ans[i][1]);
    return 0;
}
View Code

 

 

 

 

Codeforces Global Round 3

标签:cin   style   min   isp   put   src   std   clr   hid   

原文地址:https://www.cnblogs.com/bxd123/p/10962536.html

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