2020icpc南京站部分题解

目录

K Co-prime Permutation

大致题意:

经验:

代码:

Let's Play Curling

大概题意:

    代码:

E:https://blog.csdn.net/m0_50623076/article/details/111565709

F:https://blog.csdn.net/m0_50623076/article/details/111601505

 

待更新------


 

K Co-prime Permutation

大致题意:

    对0~n求一个排列组合,使得有k个数pi与对应的i互质,其余不互质;

经验:

    不要被样例蒙蔽。

    首先,对于1肯定是互质的,所以对于k=0的情况肯定不存在。

    其次,gcd(i,i+1)始终为1,gcd(i,i)(i!=1)始终为i>1。

    所以让前k-1个分别为i+1,f(k)=1。这样就完成了:

    2 3  4 … k 1 k+1 k+2 … n

代码:

#include<algorithm>

#include<iostream>



using namespace std;



int main(){

    int n,k;

    cin >> n >> k;

    if(k == 0){

       cout << "-1\n";

       return 0;

    }

    for(int i = 1;i <= n;i++){

       if(i < k){

           cout << i+1;

       }

       else if(i == k)   cout<<"1";

       else cout << i;

       if(i == n) cout<<endl;

       else cout << ' ';

    }

    return 0;

}

Let's Play Curling

大概题意:

    一个线段上,有n个红点和j个蓝点。寻找一个点c,使得满足|c-ai|<|c-bj|,j∈[1,m]。

    其实就是找红点的聚集地区。蓝点把红色划分为块,哪个块最多,哪个就是。

    代码:

#include<algorithm>

#include<iostream>



using namespace std;

typedef long long ll;

const int maxn = 1e6+50;

int a[maxn],b[maxn];

int main(){

    int t;

    cin >> t;

    int n,m;

    while(t--){

       scanf("%d%d",&n,&m);

       int t = max(n,m);

       for(int i = 0;i <=t;i++){

           a[i] = 0;b[i] = 0;

       }

       for(int i = 0;i < n;i++)  scanf("%d",&a[i]);

       for(int i = 0;i < m;i++)  scanf("%d",&b[i]);

       sort(a,a+n);

       sort(b,b+m);

       b[m] = 1e9+10;

       int maxs = 0,rec,k;

//别忘记第一个蓝点之前的红点也要计数。

       for(k = 0;k < n;k++){

           if(a[k] >= b[0])      break;

       }

       maxs = max(maxs,k);

       for(int i = 0,j = k;j < n&&i < m;i++){//n+m

           //i -blue  j-red

           while(j < n&&a[j] <= b[i])   j++;

           //j 为第一个再区间内的

           if(j >= n) break;

           rec = j;

           while(j<n&&a[j]<b[i+1]) j++;

           //j为第一个不在区间内的

           maxs = max(maxs,j-rec);

       }

       if(maxs == 0)  {

           printf("Impossible\n");

       }

       else

           printf("%d\n",maxs);

    }

    return 0;

}

 

  • 10
    点赞
  • 8
    收藏
    觉得还不错? 一键收藏
  • 3
    评论
评论 3
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值