1 条题解
-
0
自动搬运
来自洛谷,原作者为

Waddles
这个家伙很菜,什么都没有留下搬运于
2025-08-24 21:43:15,当前版本为作者最后更新于2018-10-01 20:52:32,作者可能在搬运后再次修改,您可在原文处查看最新版自动搬运只会搬运当前题目点赞数最高的题解,您可前往洛谷题解查看更多
以下是正文
这道题没有更优的解法?
那我来发一波
分成N/2组(毋庸置疑)
每一种颜色数量肯定小于N/2(毋庸置疑)
读入时将每一种展开,依次配对
这种算法实现的依据是每种颜色不超过N/2,所以第i种颜色和i+n/2配对,就可以保证不重复,且不遗漏,如果用其他的方法我觉得麻烦一些
题解区居然没有这种解法
:
#include<map> #include<cmath> #include<stack> #include<queue> #include<cstdio> #include<vector> #include<cstring> #include<iostream> #include<algorithm> using namespace std; typedef long long ll;//头文件 template<class AK>void r(AK &x){//快读 x=0; int f=0; char ch=getchar(); while(ch<'0'||ch>'9'){ f|=(ch=='-'); ch=getchar(); } while(ch>='0'&&ch<='9'){ x=(x<<1)+(x<<3)+(ch^48); ch=getchar(); } x=f?-x:x; return; } int n,m,a[1000005],top; int main(){ r(n);r(m); for(int i=1;i<=m;i++){ int x; r(x);//读入个数 while(x--)a[++top]=i;//展开 } for(int i=1;i<=n/2;i++)printf("%d %d\n",a[i],a[i+n/2]);//配对输出,就是那么简单 return 0;//结束 }
- 1
信息
- ID
- 1967
- 时间
- 1000ms
- 内存
- 125MiB
- 难度
- 3
- 标签
- 递交数
- 0
- 已通过
- 0
- 上传者