一个1到n序列,合理排序逆序对数要求是m,而且字典序要求最小;

这个题,因为数字只能用一次,所以我们可以知道什么位置放什么数逆序对的个数会增加或减少多少;

先求出最多能产生的数量,每次先输出最小的数,用总数减去减少的逆序对数;

如果不够的时候就要用大数排在前面;

vector,记得输出一个删一个;

#include<cstdio>
#include<vector>
#include<cstring>
#include<algorithm>
using namespace std;
typedef long long ll;
ll n,m;
ll now;
vector<ll> v;
int main()
{
scanf("%lld%lld",&n,&m);
for(ll i=;i<=n;i++) v.push_back(i);
ll s=n*(n-)/;
for(int i=n-;i>=;i--)
{
s-=i;
if(m>s)
{
now=m-s;
m=s;
}
else now=;
printf("%lld ",v[now]);
v.erase(v.begin()+now);
}
return ;
}

又是毕业季我什么也不想说

1到n这些数中,找到k个,使他们的GCD最大,输出GCD;

#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
int n,k;
int main()
{
scanf("%d%d",&n,&k);
printf("%d",n/k);
return ;
}

又是毕业季II

这回数字不连续而且k的值是变的;

把所有的数的公约数的数量记一下就好了

#include<cstdio>
#include<cstring>
#include<cmath>
#include<algorithm>
using namespace std;
const int maxn=1e6+;
int n,x;
int c[maxn];
int maxx;
int main()
{
scanf("%d",&n);
for(int i=;i<=n;i++)
{
scanf("%d",&x);
maxx=max(maxx,x);
int m=sqrt(x);
for(int j=;j<=m;j++)
{
if(x%j==)
{
c[j]++;
if(x/j!=j) c[x/j]++;
}
}
}
x=maxx;
for(int i=;i<=n;i++)
{
while(c[x]<i) x--;
printf("%d\n",x);
}
return ;
}

最新文章

  1. Spring基本框架
  2. JQuery制作简单的网页导航特效
  3. 普华永道高级JAVA面试记录
  4. U3D4.X版本无法安装MONODEV编辑器
  5. 有用的dede表单代码
  6. python3爬虫初探(四)之文件保存
  7. jetty-distribution-7.6.x 部署
  8. unity 基础之PhysicsManager
  9. 【转载】NativeSQL实例
  10. Django 邮件推送 解决附件中文名字乱码
  11. PHP去除Notice警告提示
  12. poj 2533 Longest Ordered Subsequence(线性dp)
  13. 将dom4j格式化为标准的xml字符串
  14. 美团点评DBProxy读写分离使用说明
  15. 在linux中导入sql文件的方法分享(使用命令行转移mysql数据库)
  16. [Leetcode] Sort, Hash -- 274. H-Index
  17. Redis的持久化机制包括RBD和AOF两种,对于这两种持久化方式各有优势
  18. String 类
  19. 建立自己的git服务器
  20. R实用小技巧

热门文章

  1. Sublim text 3 同步 eclipse 快捷键
  2. 3_PHP表达式_5_数据类型转换_类型自动转换
  3. ABAP-会计凭证替代字段GB01设置
  4. 【leetcode】366.Find Leaves of Binary Tree
  5. c# 处理串行化对象的版本变化
  6. Linux命令——ar
  7. 静态库 VS 动态库
  8. STM32 HAL库学习系列第8篇---回调函数总结
  9. [原创]extjs htmleditor增加截图快速粘贴功能 插件
  10. Idea中用来遍历list集合的快捷键