CodeForces 686B - Little Robber Girl's Zoo
2016-08-28 12:02
288 查看
题意:将一个n(1 <= n <= 100)个元素的序列排成非递减序列,每次操作可以指定区间[ L,R ](区间内元素个数为偶数),将区间内第一项与第二项交换,第三项与第四项交换,第五项与第六项……在2W次内完成排序,输出每次操作。
瞎搞即可,不断检查相邻元素是否满足 前者>=后者,不满足即交换,直到序列满足条件位置(n最大为100绝对不会超过2W步)
#include<cstdio>
#include<cstring>
#include<cctype>
#include<cstdlib>
#include<cmath>
#include<iostream>
#include<sstream>
#include<iterator>
#include<algorithm>
#include<string>
#include<vector>
#include<set>
#include<map>
#include<deque>
#include<queue>
#include<stack>
#include<list>
#define fin freopen("in.txt", "r", stdin)
#define fout freopen("out.txt", "w", stdout)
#define pr(x) cout << #x << " : " << x << " "
#define prln(x) cout << #x << " : " << x << endl
typedef long long ll;
typedef unsigned long long llu;
const int INT_INF = 0x3f3f3f3f;
const int INT_M_INF = 0x7f7f7f7f;
const ll LL_INF = 0x3f3f3f3f3f3f3f3f;
const ll LL_M_INF = 0x7f7f7f7f7f7f7f7f;
const double pi = acos(-1.0);
const double EPS = 1e-6;
const int dx[] = {0, 0, -1, 1};
const int dy[] = {-1, 1, 0, 0};
const ll MOD = 1e9 + 7;
const int MAXN = 100 + 10;
const int MAXT = 10000 + 10;
using namespace std;
int n, a[MAXN];
int main(){
while(scanf("%d", &n) == 1){
for(int i = 1; i <= n; ++i) scanf("%d", a + i);
bool flag = true;
while(flag){
flag = false;
for(int i = 1; i < n; ++i)
if(a[i] > a[i + 1]){
flag = true;
swap(a[i], a[i + 1]);
printf("%d %d\n", i, i + 1);
}
}
}
return 0;
}
瞎搞即可,不断检查相邻元素是否满足 前者>=后者,不满足即交换,直到序列满足条件位置(n最大为100绝对不会超过2W步)
#include<cstdio>
#include<cstring>
#include<cctype>
#include<cstdlib>
#include<cmath>
#include<iostream>
#include<sstream>
#include<iterator>
#include<algorithm>
#include<string>
#include<vector>
#include<set>
#include<map>
#include<deque>
#include<queue>
#include<stack>
#include<list>
#define fin freopen("in.txt", "r", stdin)
#define fout freopen("out.txt", "w", stdout)
#define pr(x) cout << #x << " : " << x << " "
#define prln(x) cout << #x << " : " << x << endl
typedef long long ll;
typedef unsigned long long llu;
const int INT_INF = 0x3f3f3f3f;
const int INT_M_INF = 0x7f7f7f7f;
const ll LL_INF = 0x3f3f3f3f3f3f3f3f;
const ll LL_M_INF = 0x7f7f7f7f7f7f7f7f;
const double pi = acos(-1.0);
const double EPS = 1e-6;
const int dx[] = {0, 0, -1, 1};
const int dy[] = {-1, 1, 0, 0};
const ll MOD = 1e9 + 7;
const int MAXN = 100 + 10;
const int MAXT = 10000 + 10;
using namespace std;
int n, a[MAXN];
int main(){
while(scanf("%d", &n) == 1){
for(int i = 1; i <= n; ++i) scanf("%d", a + i);
bool flag = true;
while(flag){
flag = false;
for(int i = 1; i < n; ++i)
if(a[i] > a[i + 1]){
flag = true;
swap(a[i], a[i + 1]);
printf("%d %d\n", i, i + 1);
}
}
}
return 0;
}
相关文章推荐
- Codeforces Round #359 (Div. 2) B. Little Robber Girl's Zoo
- Codeforces Round #359 (Div. 2) B. Little Robber Girl's Zoo
- CF686B A - Little Robber Girl's Zoo
- B. Little Robber Girl's Zoo
- Codeforces Round #359 (Div. 2) B. Little Robber Girl's Zoo
- codeforces round 359# div.2 B. Little Robber Girl's Zoo
- CodeForces 276E - Little Girl and Problem on Trees 区间更新..N+1个线段树
- 【Codeforces 276C】Little Girl and Maximum Sum
- [CodeForces 276D] Little Girl and Maximum XOR (构造+脑洞)
- Codeforces 2016 ACM Amman Collegiate Programming Contest B. The Little Match Girl(贪心)
- Codeforces 2016 ACM Amman Collegiate Programming Contest B. The Little Match Girl(贪心)
- B. Little Robber Girl's Zoo(CF#359)
- CodeForces 276D – Little Girl and Maximum XOR 贪心
- CodeForces - 276C Little Girl and Maximum Sum
- codeforces 276D D. Little Girl and Maximum XOR(贪心+dp+数论)
- Codeforces Round #359 (Div. 2) B. Little Robber Girl's Zoo(水题)
- CodeForces 276E Little Girl and Problem on Trees 树状数组
- CodeForces 276 D.Little Girl and Maximum XOR(位运算)
- CodeForces 258B Little Elephant and Elections 数位DP
- Codeforces276E:Little Girl and Problem on Trees