题意:给你 n 和 m,求一个1-n的排列,使得∑gcd(Ai,Ai+1) 恰为第  m 小.

析:可以想到最小的就是相邻都互质,然后依次,第 m 小就可以有一个是gcd为 k,然后其他的为1喽。

那么我们就可以想到把 m 和2*m 拿出来,然后让其他的都相邻,那么就一定是gcd为1.

代码如下:

#pragma comment(linker, "/STACK:1024000000,1024000000")
#include <cstdio>
#include <string>
#include <cstdlib>
#include <cmath>
#include <iostream>
#include <cstring>
#include <set>
#include <queue>
#include <algorithm>
#include <vector>
#include <map>
#include <cctype>
#include <cmath>
#include <stack>
//#include <tr1/unordered_map>
#define freopenr freopen("in.txt", "r", stdin)
#define freopenw freopen("out.txt", "w", stdout)
using namespace std;
//using namespace std :: tr1; typedef long long LL;
typedef pair<int, int> P;
const int INF = 0x3f3f3f3f;
const double inf = 0x3f3f3f3f3f3f;
const LL LNF = 0x3f3f3f3f3f3f;
const double PI = acos(-1.0);
const double eps = 1e-8;
const int maxn = 1e6 + 5;
const LL mod = 10000000000007;
const int N = 1e6 + 5;
const int dr[] = {-1, 0, 1, 0, 1, 1, -1, -1};
const int dc[] = {0, 1, 0, -1, 1, -1, 1, -1};
const char *Hex[] = {"0000", "0001", "0010", "0011", "0100", "0101", "0110", "0111", "1000", "1001", "1010", "1011", "1100", "1101", "1110", "1111"};
inline LL gcd(LL a, LL b){ return b == 0 ? a : gcd(b, a%b); }
int n, m;
const int mon[] = {0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
const int monn[] = {0, 31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
inline int Min(int a, int b){ return a < b ? a : b; }
inline int Max(int a, int b){ return a > b ? a : b; }
inline LL Min(LL a, LL b){ return a < b ? a : b; }
inline LL Max(LL a, LL b){ return a > b ? a : b; }
inline bool is_in(int r, int c){
return r >= 0 && r < n && c >= 0 && c < m;
} int main(){
int T; cin >> T;
for(int kase = 1; kase <= T; ++kase){
scanf("%d %d", &n, &m);
printf("Case #%d: ", kase);
printf("%d %d", m*2, m);
for(int i = m-1; i; --i) printf(" %d", i);
for(int i = m+1; i <= n; ++i) if(i != m*2)
printf(" %d", i);
printf("\n");
}
return 0;
}

最新文章

  1. 如何在 Visual Studio 中使用 Git 同步代码到 CodePlex
  2. Unity3D热更全书
  3. 在微信中实现app软件中账号注册的功能实现
  4. bzoj3272 3638
  5. iOS开发:Swift多线程NSThread的使用
  6. Win32非递归遍历和搜索文件以及目录算法
  7. return 和 exit
  8. memcached几个easy被忽略但很实用的命令
  9. VCMI Mods list
  10. Python学习之collections module-defaultdict()
  11. 基于visual Studio2013解决面试题之0710求方优化
  12. Mac下添加java环境变量
  13. javascript 中this的使用场景全
  14. Java中的4个并发工具类 CountDownLatch CyclicBarrier Semaphore Exchanger
  15. Java多线程学习(二)---线程创建方式
  16. MVC简单用户登录授权认证
  17. 现代程序设计 homework-10
  18. java.util.Stack类中的peek()方法
  19. Java18-java语法基础——集合框架
  20. POJ1742--Coins(动态规划)

热门文章

  1. Intersection of Two Linked Lists(链表)
  2. Java日志框架-logback配置文件参考(转)
  3. json解析bug之ERROR ExceptionController:185 - not close json text, token : :
  4. 【c++】面向对象程序设计之访问控制与继承
  5. 使用MySQL Workbench进行数据库设计——MySQL Workbench用法总结
  6. Android进程绝杀技--forceStop(转)
  7. 简单JS全选、反选代码
  8. mysql字段A复制到字段B,并替换指定字符
  9. c#Winform程序调用app.config文件配置数据库连接字符串 SQL Server文章目录 浅谈SQL Server中统计对于查询的影响 有关索引的DMV SQL Server中的执行引擎入门 【译】表变量和临时表的比较 对于表列数据类型选择的一点思考 SQL Server复制入门(一)----复制简介 操作系统中的进程与线程
  10. Android使用adb获得activity堆栈信息