codeforce 277.5 A

排序的题从来没有搞懂过

#include <iostream>

#include <algorithm>

#include <cstdio>

#include <cstring>

using namespace std;

#define  N 3001

struct node {

int s, e;

}edge[N];

int a[N];

int main() {

int n;

while(cin >> n) {

for(int i = 0; i < n; i ++)

cin >> a[i];

int k = 0;

for(int i = 0; i < n - 1; i ++) {

int Mi = a[i];

int mark = i;

for(int j = i + 1; j < n; j ++) {

if(a[j] < Mi) {

Mi = a[j];

mark = j;

}

}

if(mark != i) {

swap(a[i], a[mark]);

edge[k].s=i;

edge[k++].e=mark;

}

}

cout << k << endl;

for(int i = 0; i < k; i ++)

cout << edge[i].s << " " << edge[i].e << endl;

}

}

时间: 2024-10-14 04:00:54

codeforce 277.5 A的相关文章

CodeForce 448C 木片填涂问题

题目大意:有多片木片需要填涂,可以每次横着涂一行,也可以一次涂一列,当然你涂一行时遇到中间长度不够高的木片,填涂到此中断 这题目运用dfs能更容易的解出,虽然还是十分不容易理解 1 #include <iostream> 2 3 using namespace std; 4 5 #define N 5010 6 int a[N],n; 7 8 int Min(int c,int d) 9 { 10 return c<d?c:d; 11 } 12 int dfs(int c,int d,i

Codeforce 水题报告(2)

又水了一发Codeforce ,这次继续发发题解顺便给自己PKUSC攒攒人品吧 CodeForces 438C:The Child and Polygon: 描述:给出一个多边形,求三角剖分的方案数(n<=200). 首先很明显可能是区间dp,我们可以记f[i][j]为从i到j的这个多边形的三角剖分数,那么f[i][j]=f[i][k]*f[j][k]*(i,j,k是否为1个合格的三角形) CodeForces 438D:The Child and Sequence 描述:给一个序列,要求支持区

codeforce 285 div2 D 题解

codeforce 285 div2 D 题解 说明 这道题目是看了思路分析才知道的,关键问题在于数据量过大,需要快速检索的同时不能辅助空间过大. 因此利用了下面3种方法结合解决该问题 康拓展开与逆康拓展开 树状数组 二分查找 代码 /** * @brief Codeforces Round #285 (Div. 2) d * @file d.cpp * @author mianma * @created 2015/01/27 18:18 * @edited 2015/01/29 22:45 *

codeforce Pashmak and Buses(dfs枚举)

1 /* 2 题意:n个同学,k个车, 取旅游d天! 3 要求所有的学生没有两个或者两个以上的在同一辆车上共同带d天! 输出可行的方案! 4 5 对于d行n列的矩阵,第i行第j列表示的是第i天第j个同学所在的车号! 6 也就是保证所有行不全相同,即每一列都是不相同的! 7 如果每一列都不相同就是表示第j个同学(第j列)在这d天中不会和其他同学(列)在这d天中 都在同一辆车中! 8 9 思路:对于每一列我们枚举d天该学生所在的车号!它的下一列只保证有一个元素和它不同就行了!依次下去! 10 11

codeforce 605BE. Freelancer&#39;s Dreams

题意:给你n个工程,做了每个工程相应增长x经验和y钱.问你最少需要多少天到达制定目标.时间可以是浮点数. 思路:杜教思路,用对偶原理很简易.个人建议还是标准解题法,凸包+线性组合. 1 #include<iostream> 2 #include<string> 3 #include<algorithm> 4 #include<cstdlib> 5 #include<cstdio> 6 #include<set> 7 #include&

&lt;swustoj&gt;?id=277 统计二进制数中的1的个数

链接http://acm.swust.edu.cn/problem/277/ #include <stdio.h> int main() { int sum,num; num=0; scanf("%d",&sum); while(sum) { if(sum%2==1) { num++; } sum/=2; } printf("%d\n",num); return 0; }

Codeforce 214 Div 2 B.Hometask

题目描述: Description Furik loves math lessons very much, so he doesn't attend them, unlike Rubik. But now Furik wants to get a good mark for math. For that Ms. Ivanova, his math teacher, gave him a new task. Furik solved the task immediately. Can you? Y

Codeforce 22B Bargaining Table

B. Bargaining Table Bob wants to put a new bargaining table in his office. To do so he measured the office room thoroughly and drew its plan: Bob's office room is a rectangular room n?×?m meters. Each square meter of the room is either occupied by so

Codeforce 9C - Hexadecimal&#39;s Numbers

One beautiful July morning a terrible thing happened in Mainframe: a mean virus Megabyte somehow got access to the memory of his not less mean sister Hexadecimal. He loaded there a huge amount of n different natural numbers from 1 to n to obtain tota