Codefoces 432 C. Prime Swaps(水)】的更多相关文章

哥德巴赫猜想: 任一大于2的偶数,都可表示成两个素数之和. 任一大于5的整数都可写成三个质数之和. 贪心取尽可能大的素数..... C. Prime Swaps time limit per test 2 seconds memory limit per test 256 megabytes input standard input output standard output You have an array a[1], a[2], ..., a[n], containing distinc…
思路:从前往后想将1调整好,在调整2....这样平均每次有五次机会调整,并且有相当一部分可能都用不到五次,能够一试.ac 代码: #include<iostream> #include<cstdio> #include<cmath> #include<map> #include<queue> #include<cstring> #include<algorithm> using namespace std; const i…
版权声明:本文为博主原创文章,未经博主同意不得转载. https://blog.csdn.net/u011328934/article/details/26094917 题目连接:Codefoces 432C Prime Swaps 题目大意:给出一个序列.长度为n,要求用5n以内的交换次数使得序列有序.而且交换的i,j两个位置的数时要满足,j−i+1为素数. 解题思路:a数组为相应的序列,b数组为相应的有序序列,p为相应数的位置.每次从有序序列最小的位置開始,该为必须放b[i]才对.所以p[b…
POJ.2739 Sum of Consecutive Prime Numbers(水) 代码总览 #include <cstdio> #include <cstring> #include <vector> #include <cmath> #define nmax 10005 using namespace std; int prime[nmax],n; vector<int> vprime; void init() { memset(pri…
Final Pan's prime numbers Time Limit: 1000MS   Memory Limit: 65535KB   64bit IO Format: %lld & %llu Submit Status Description Final Pan likes prime numbers very much. One day, he want to find the super prime numbers.A prime numbers $n$($n$>4) is a…
Description You have an array a[1], a[2], ..., a[n], containing distinct integers from 1 to n. Your task is to sort this array in increasing order with the following operation (you may need to apply it multiple times): choose two indexes, i and j (1 …
C. Bear and Prime 100 题目连接: http://www.codeforces.com/contest/680/problem/C Description This is an interactive problem. In the output section below you will see the information about flushing the output. Bear Limak thinks of some hidden number - an i…
题目链接:https://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem&problem=1141 题意:判断区间[a,b]的f(i)是否为素数,f(i)=i*i+i+40: 思路:打个表,然后注意精度: #include<bits/stdc++.h> using namespace std; #define ll long long #define esp…
题目链接:http://codeforces.com/contest/432/problem/C 首先由题意分析出:这些数是从1到n且各不相同,所以最后结果肯定是第i位的数就是i. 采用这样一种贪心策略:从1到n枚举每一位.如果第i位不是i,那么就把i 从它所在的位置移动到第i 位,每次移动的距离要选取符合要求的最大的素数,那么由哥德巴赫猜想可以知道,最后肯定小于5次移动就移好了.每一位都这么移就行了.这过程中记录一下每次谁和谁交换位置就行了. 我把x[],y[]开成了maxn而导致了RE,改成…
题意:给定一个数 n,求它后一个素数和前一个素数差. 析:先打表,再二分查找. 代码如下: #pragma comment(linker, "/STACK:1024000000,1024000000") #include <cstdio> #include <string> #include <cstdlib> #include <cmath> #include <iostream> #include <cstring&…