1621
来源:互联网 发布:华云数据待遇如何知乎 编辑:程序博客网 时间:2024/06/04 00:36
- 题目大意
- 样例
- input
- output
- 解释
- 思路
- 代码
- Hit
题目大意
传送门
任务:从0出发,访问0~n各一次,可以在任意一点终止,需要用票才能从一个点到另一个点。
有三种票,跳跃长度分别为1 2 3,有a,b,c张(3<= a,b,c<=5000)并且n=a+b+c。
每张票只能用一次。输入保证有解。
样例
input
2
3 3 3
3 4 3
output
0 3 1 2 5 4 6 9 7 8
0 3 1 2 5 4 6 9 7 8 10
解释
思路
首先引入一个概念叫做同余类,以正整数m为模,则任何整数必然与0,1,2,3,…,m-1之一同余,将同余的数归为一类。
比如当m为4的时候。
{… -4 0 4 8 …}
{… -3 1 5 9 …}
{… -2 2 6 10 …}
{… -1 3 7 11 …}
首先考虑这样的一个问题:
如果只有一个a和n个b,然后就可以先跳2步,0 2 4 6 8,然后跳一个1,改变同余类,然后往回跳,结束。
引入了c,首先就把c消掉。
当c%3为0时,可以先往右调c/3个3,往右跳1步,往左跳c/3个3,往右跳1步,往右跳c/3个3,到达c/3*3+2的位置,这个时候c已经用完了。
c%3不为0的时候同理。
代码
#include<cstdio>#include<map>#include<queue>#include<cstring>#include<iostream>#include<cstring>#include<algorithm>#include<vector>#include<stdlib.h>#include <math.h>#include <stack>using namespace std;const int maxn = 5005;int main(){ int a,b,c; int CaseNum; scanf("%d",&CaseNum); while(CaseNum--){ scanf("%d%d%d",&a,&b,&c); int pos = 0; printf("0"); if(c%3==0){ for(int i=0;i<c/3;i++) pos+=3,printf(" %d",pos); pos+=1,printf(" %d",pos); for(int i=0;i<c/3;i++) pos-=3,printf(" %d",pos); pos+=1,printf(" %d",pos); for(int i=0;i<c/3;i++) pos+=3,printf(" %d",pos); a-=2; } else if(c%3==1){ pos+=2,printf(" %d",pos); for(int i=0;i<c/3;i++) pos+=3,printf(" %d",pos); pos+=1,printf(" %d",pos); for(int i=0;i<c/3;i++) pos-=3,printf(" %d",pos); pos-=2,printf(" %d",pos); for(int i=0;i<c/3+1;i++) pos+=3,printf(" %d",pos); a-=1;b-=2; } else if(c%3==2){ for(int i=0;i<c/3+1;i++) pos+=3,printf(" %d",pos); pos-=1,printf(" %d",pos); for(int i=0;i<c/3;i++) pos-=3,printf(" %d",pos); pos-=1,printf(" %d",pos); for(int i=0;i<c/3+1;i++) pos+=3,printf(" %d",pos); a-=2; } for(int i=0;i<a-1;i++) pos+=1,printf(" %d",pos); for(int i=0;i<b/2+b%2;i++)pos+=2,printf(" %d",pos); if(b%2==1)pos-=1,printf(" %d",pos); else pos+=1,printf(" %d",pos); for(int i=0;i<b/2;i++)pos-=2,printf(" %d",pos); printf("\n"); }}/*input23 3 33 4 3output0 3 1 2 5 4 6 9 7 80 3 1 2 5 4 6 9 7 8 10*/
Hit
阅读全文
0 0
- 1621
- 1621 混合牛奶
- HRBUST 1621 迷宫问题II
- Hdu 1621 - Pipe Fitters 计算几何
- PLSQL Developer V9.0.2.1621 注册码
- PLSQL Developer V9.0.2.1621 注册码
- PLSQL Developer V9.0.2.1621 注册码
- 南邮 OJ 1621 矩阵取数游戏
- 51nod 1621 花钱买车牌 (贪心)
- 51Nod-1621-花钱买车牌
- 51nod 1621 花钱买车牌
- BZOJ 1621: [Usaco2008 Open]Roads Around The Farm分岔路口
- BZOJ 1621: [Usaco2008 Open]Roads Around The Farm分岔路口
- 【BZOJ 1621】 [Usaco2008 Open]Roads Around The Farm分岔路口
- 30天自己制作操作系统中二进制编辑器BZ-1621
- 【哈工大oj】1621 - 迷宫问题II(bfs,优先队列)
- BZOJ-1621-[Usaco2008 Open]Roads Around The Farm分岔路口
- BZOJ 1621: [Usaco2008 Open]Roads Around The Farm分岔路口
- Spring MVC DispatcherServlet详解
- 组合选择器之多元素选择器
- 09 uboot的配置编译主过程分析
- Python中的sorted函数以及operator.itemgetter函数
- Minimum Moves to Equal Array Elements
- 1621
- 逻辑地址转换为物理地址
- bi cube
- Spring AOP之概念
- C++中const用法
- ubuntu16 下安装 python3 setuptools 以及 pip3 以及numpy
- java web开发中文乱码解决方法详解
- C++ 模板
- 搜索练习题G-07