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个,那么总组合方式是多少种? 总组合方式就 ...
随机推荐
- 如何重启Cloudera Manager?
为什么重启: 突然发现ClouderaManager的webui访问不了了…… 我使用netstat看了一下我的webui监听端口,发现尼玛N多CLOSE_WAIT,网上查了一下是Socket关闭有问 ...
- 合成模式(Composite)-结构型
原理 合成模式属于对象的结构模式,有时又叫做“部分——整体”模式.合成模式将对象组织到树结构中,可以用来描述整体与部分的关系.合成模式可以使客户端将单纯元素与复合元素同等看待. 有时候又叫做部分-整体 ...
- BZOJ2459 : [BeiJing2011]神秘好人
线段树每个节点维护d[4][4]表示四个顶点之间的最短路,合并时用Floyed合并,查询时分三段然后合并. #include<cstdio> #define N 100010 struct ...
- ubuntu apt源
deb http://archive.ubuntu.com/ubuntu/ vivid main restricted universe multiversedeb http://archive.ub ...
- JAVA生成RSA非对称型加密的公钥和私钥(利用JAVA API)
非对称型加密非常适合多个客户端和服务器之间的秘密通讯,客户端使用同一个公钥将明文加密,而这个公钥不能逆向的解密,密文发送到服务器后有服务器端用私钥解密,这样就做到了明文的加密传送. 非对称型加密也有它 ...
- jquery-mobile表单提交问题
关于使用jquery-mobile表单提交遇到的问题 当你使用了jquery-mobile的时候,如果你在前台提交一个了一个form表单,而在后台你处理完业务逻辑之后想要重定向到另一个方法或页 ...
- Mui - 全局css
头部(mh) <header class="mui-bar mui-bar-nav"> <a class="mui-action-back mui-ic ...
- win7(32/64)+apache2.4+php5.5+mysql5.6 环境搭建配置
引用自:http://blog.csdn.net/z_cf1985/article/details/22454749 环境:win7 32.(64位的同理,下载相关软件必须是对应的64位版本) ...
- DNS服务器的配置与应用: BIND9 的安装与配置
3. BIND9 的安装与配置 3.1 bind简介 BIND (Berkeley Internet Name Domain)是Domain Name System (DNS) 协议的一个实现,提供了 ...
- Export-XLSX PowerShell generate real Excel XLSX files without Excel and COM
http://gallery.technet.microsoft.com/scriptcenter/Export-XLSX-PowerShell-f2f0c035