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个,那么总组合方式是多少种? 总组合方式就 ...
随机推荐
- 模拟 POJ 1068 Parencodings
题目地址:http://poj.org/problem?id=1068 /* 题意:给出每个右括号前的左括号总数(P序列),输出每对括号里的(包括自身)右括号总数(W序列) 模拟题:无算法,s数组把左 ...
- BZOJ3931 [CQOI2015]网络吞吐量(最大流)
没啥好说的,有写过类似的,就是预处理出最短路上的边建容量网络. #include<cstdio> #include<cstring> #include<queue> ...
- BZOJ3738 : [Ontak2013]Kapitał
$C_{N+M}^N=\frac{(N+M)!}{N!M!}$ 考虑求出$ans\bmod 10^9$的值 $10^9=2^9\times5^9$ 以$2^9$为例,先预处理出$1$..$2^9$中不 ...
- Distributed RPC —— 分布式RPC
This tutorial showed how to do basic stream processing on top of Storm. There's lots more things you ...
- Java中的HashTable详解
Hashtables提供了一个很有用的方法可以使应用程序的性能达到最佳. Hashtables(哈 希表)在计算机领域中已不 是一个新概念了.它们是用来加快计算机的处理速度的,用当今的标准来处理,速度 ...
- javascript,HTML,PHP,ASP做301跳转代码 SEO优化设置
URL HTTP Redirection URL http redirection is an automatic URL change operation from one URL to anoth ...
- 移动WEB测试工具 Adobe Edge Inspect
要用到的内容: Adobe Edge Code CC https://creative.adobe.com/products/code?promoid=KFKML Adobe Edge In ...
- 为tomcat 安装 native 和配置apr
yum install -y apr-devel openssl-devel gcc 安装native cd /lxyy/tomcat7/bin tar zxvf tomcat-native.tar. ...
- 【SPOJ】694. Distinct Substrings
http://www.spoj.com/problems/DISUBSTR/ 题意:求字符串不同子串的数目. #include <bits/stdc++.h> using namespac ...
- 发生了COMException 异常来自 HRESULT:0x80040228
异常信息: 发生了COMException 异常来自 HRESULT:0x80040228 原因解决方法:窗体中忘记放LicenseControl控件.,加上LicenseControl即可