oj 1031 random permutation
Problem A: Random Permutations
Time Limit: 1 Sec Memory Limit: 128 MB Submit: 91 Solved: 54
Description
随机排列生成算法 (运行a.exe输出数字的个数,运行a.exe test时输出为一次随机的排列)
Input
The input will be a list of integers
Output
The number of the integers
Sample Input
Sample Output
#include<iostream>
#include<cstdlib>
#include<ctime>
using namespace std;
int seed=time();
int b[]={};
int test(int b[],int i,int temp)
{
for (int j=;j<i;j++)
{
if (b[j]==temp) return -;
}
return ;
}
void give_test(int b[],int temp,int i,int n)
{
seed++;
srand(seed);
temp=rand()%n;
if (test(b,i,temp)==-)
{
seed++;
give_test(b,temp,i,n);
}
else b[i]=temp;
}
void random_permute(int a[],int n)
{
srand(seed);
b[]=rand()%n;
int temp=;
for (int i=;i<n;i++)
{
give_test(b,temp,i,n);
}
for (int i=;i<n;i++)
cout<<a[b[i]]<<" ";
}
int main(int argc,char *argv[])
{
int n;
cin>>n;
int a[];
for (int i=;i<n;i++)
cin>>a[i];
random_permute(a,n);
cout<<n<<endl;
return ;
}
验证可行
—>修改符合oj设计(argc,argv……受不了了,先睡……改天再说)
—>逗了,原题未输入元素个数……改一改再说
oj 1031 random permutation的更多相关文章
- numpy.random.shuffle()与numpy.random.permutation()的区别
参考API:https://docs.scipy.org/doc/numpy/reference/routines.random.html 1. numpy.random.shuffle() AP ...
- Python之np.random.permutation()函数的使用
官网的解释是:Randomly permute a sequence, or return a permuted range. 即随机排列序列,或返回随机范围.我的理解就是返回一个乱序的序列.下面通过 ...
- np.random.shuffle(x)与np.random.permutation(x)
来自:https://blog.csdn.net/brucewong0516/article/details/79012233 将数组打乱随机排列 两种方法: np.random.shuffle(x) ...
- Light OJ 1031 - Easy Game(区间dp)
题目链接:http://www.lightoj.com/volume_showproblem.php?problem=1031 题目大意:两个选手,轮流可以从数组的任意一端取值, 每次可以去任意个但仅 ...
- LeetCode OJ 31. Next Permutation
Implement next permutation, which rearranges numbers into the lexicographically next greater permuta ...
- 九度oj 1031 xxx定律 2009年浙江大学计算机及软件工程研究生机试真题
题目1031:xxx定律 时间限制:1 秒 内存限制:32 兆 特殊判题:否 提交:5153 解决:3298 题目描述: 对于一个数n,如果是偶数,就把n砍掉一半:如果是奇数,把n变成 3*n ...
- LeetCode OJ:Next Permutation(下一排列)
Implement next permutation, which rearranges numbers into the lexicographically next greater permuta ...
- 九度OJ 1031:xxx定律 (基础题)
时间限制:1 秒 内存限制:32 兆 特殊判题:否 提交:6058 解决:3816 题目描述: 对于一个数n,如果是偶数,就把n砍掉一半:如果是奇数,把n变成 3*n+ 1后砍掉一半,直到该数 ...
- Light OJ 1060 - nth Permutation(组合数)
题目大意: 给你一个字符串,问这个字符串按照特定顺序排列之后,第n个字符串是哪个? 题目分析: 首先我们要会求解总个数.也就是共有len个字符,每个字符有ki个,那么总组合方式是多少种? 总组合方式就 ...
随机推荐
- include、include_once与require、require_once区别
include与require的区别 include在引入不存文件时产生一个警告且脚本还会继续执行,而require则会导致一个致命性错误且脚本停止执行. <?php include 'no.p ...
- sql 遍历结果print和表格形式
select * from tb_province --省 pID pName1 北京市2 天津市3 上海市4 重庆市5 河北省6 山西省....... select * from tb_city - ...
- node工具--express
//使用supervisor Connect是基于HTTP米快创建的:Express则是基于Connect上创建的: 绝大多数web服务器和浏览器之间的任务是通过url和method完成的,两者的组 ...
- EntityFramework 6.0< Code First > 连接 Mysql数据库
网上有很多关于用EntityFrame来连接Mysql数据库的教程,可是很多并不靠谱,转载的太多了.找了很久,总算是配置好了,现在分享一下. 一,安装: 1.开发环境: VS2013与EF6 ...
- jmx远程访问权限设置
1.复制jdk提供的jmx帐号和密码配置文件模板到tomcat的conf目录: cp $JAVA_HOME/jre/lib/management/jmxremote.* tomcat/conf 2.重 ...
- 转:jQuery Ajax 实例 全解析
jQuery确实是一个挺好的轻量级的JS框架,能帮助我们快速的开发JS应用,并在一定程度上改变了我们写JavaScript代码的习惯. 废话少说,直接进入正题,我们先来看一些简单的方法,这些方法都是对 ...
- iOS移动开发周报-第23期
iOS移动开发周报-第23期 [摘要]:本期iOS移动开发周报带来如下内容:苹果发出9月9日发布会邀请函,AFNetworking2.0源码解析,objc与鸭子对象,Protecting iOS Ap ...
- U-Mail邮件服务系统任意文件上传+执行漏洞(runtime缺陷与验证绕过)
http://www.wooyun.org/bugs/wooyun-2010-061859
- IE6 BUG 汇总
1.IE6双倍边距bug 当页面内有多个连续浮动时,如本页的图标列表是采用左浮动,此时设置li的左侧margin值时,在最左侧呈现双倍情况.如外边距设置为10px, 而左侧则呈现出20px,解决它的方 ...
- Redis在windows环境下的部署
一.下载 官网地址:http://redis.io/download Git地址:https://github.com/MSOpenTech/redis 注:官方无windows版本,需要window ...