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个,那么总组合方式是多少种? 总组合方式就 ...
随机推荐
- LR破解版录制手机脚本
LR破解版录制手机脚本 最近在网上听到好多童鞋都在问如何用LR做手机性能测试,恰好自己对这方面也挺感兴趣,经过查阅很多资料,形成此文档以做备注~!如果有感觉我写的不对的地方,敬请指正,谢谢~! ...
- vi-11
vi编辑器linux命令大全 作者:xiaoru 出处:本站整理 发布时间:2013-04-29 13:20:23 - vi就是linux命令行下的最著名的编辑器之一,Vim常被称作“程序 ...
- SU suplane命令学习
各位博友,不足之处,批评指正! 用其他软件打开看看, 注意:下图中应该是倾角,dip=Δt/Δx,单位为ms/traces,
- BZOJ2735 : 世博会
$|x_1-x_2|+|y_1-y_2|=\max(|(x_1+y_1)-(x_2+y_2)|,|(x_1-y_1)-(x_2-y_2)|)$ 将坐标$(x,y)$逆变换为$(\frac{x+y}{2 ...
- Linux Mint 没有 language support 语言支持解决方案
打开新立得软件管理器在右边找到有关语言的安装后,language support就会出现
- 移动平台webApp的meta标签-----神奇的功效
对于桌面平台web布局中大家对meta标签再熟悉不过了,它永远位于 head 元素内部,对做SEO的朋友一定对meta有种特殊的感情吧,今天我们就来说说移动平台的meta标签,在移动平台meta标签究 ...
- javascript大全
事件源对象 event.srcElement.tagName event.srcElement.type 捕获释放 event.srcElement.setCapture(); event.srcEl ...
- python中迭代器和生成器
l=[1,2,3,4] for n in l: print n 在看上面这段代码的时候,我们没有显式的控制列表的偏移量,就可以自动的遍历了整个列表对象.那么for 语句是怎么来遍历列表l的呢?要回答这 ...
- Function Scope
JavaScript’s function scope means that all variables declared within a function are visi-ble through ...
- dos界面下执行java文件将错误输出到一个文本小技巧
如果dos下执行java出现错误,把错误记录到一个文档 正确时如图,输出结果为hello,我把String的s改为小写,出现错误,用2>命令输出到error.txt在当前目录就出现了error. ...