GCJ——Crazy Rows (2009 Round 2 A)】的更多相关文章

题意: 给定一个N*N的矩阵,由0,1组成,只允许交换相邻的两行,把矩阵转化为下三角矩阵(对角线上方全是0),最少需要多少次交换?(保证可以转化为下三角矩阵) Large: N<=40 解析: 假如每一行的1的个数都是不相同的,即,最终答案中的矩阵是唯一的,这就相当于求对给定数组冒泡排序需要几次交换一样.但显然,题目没有如此保证. 方法是贪心法:(策略不给出证明) 从第一行到最后一行依次满足,因为可以满足前面行的也一定可以满足后面的,所以每次只需要找到可以满足当前行的最近的就可以了. 预处理最后…
https://code.google.com/codejam/contest/204113/dashboard 题目大意: 给你一个矩阵,让你转化为下三角矩阵,每次只能交换相邻的行,求最小的交换次数. 思路: 一开始觉得记录每一行最后一个1的位置,然后相邻交换排序可以直接冒泡法(甚至可以nlogn的合并排序),结果交上去错的. 想了想因为每一行最后一个1已经满足j<=i了,所以..(设行i列j) 那么就只好贪心啦,每次选最近的要交换的. #include<cstdio> #includ…
Problem You are given an N x N matrix with 0 and 1 values. You can swap any two adjacent rows of the matrix. Your goal is to have all the 1 values in the matrix below or on the main diagonal. That is, for each X where 1 ≤ X ≤ N, there must be no 1 va…
血崩- - /* CodeForces 839B - Game of the Rows [ 贪心,分类讨论] | Codeforces Round #428 (Div. 2) 注意 2 7 2 2 2 2 2 2 2 这组- - */ #include <bits/stdc++.h> using namespace std; int n, n2, n4, a[105], k; bool solve() { n2 = 2*k; n4 = k; for (int i = 1; i <= n;…
Problem You are given an N x N matrix with 0 and 1 values. You can swap any two adjacent rows of the matrix. Your goal is to have all the 1 values in the matrix below or on the main diagonal. That is, for each X where 1 ≤ X ≤ N, there must be no 1 va…
Problem In a kingdom there are prison cells (numbered 1 to P) built to form a straight line segment. Cells number i and i+1 are adjacent, and prisoners in adjacent cells are called "neighbours." A wall with a window separates adjacent cells, and…
GCJ 271 [题目大意] Minimum Scalar Product 有两个东西(滑稽)v1=(x1,x2,x3,……,xn)和v2=(y1,y2,……yn),允许任意交换v1和v2中各数字的顺序. 请计算x1y1+……+xnyn的最小值 [输入样例(第一行为n,第二行为v1,第三行为v2)] 3 1 3 -5 -2 4 1 [输出样例(直接输出最小值)] -25 [数据范围] 稍微大一点的:100<=n<=800     -100000<=x1,y1<=100000 [解题…
POJ 1852 Ants POJ 2386 Lake Counting POJ 1979 Red and Black AOJ 0118 Property Distribution AOJ 0333 Ball POJ 3009 Curling 2.0 AOJ 0558 Cheese POJ 3669 Meteor Shower AOJ 0121 Seven Puzzle POJ 2718 Smallest Difference POJ 3187 Backward Digit Sums POJ 3…
今天组里有个同事说可以查看innodb buffer pool每个表和索引占的大小,为此我搜了下,还真有方法,记录下. innodb buffer pool有几个目的: 缓存数据--众所周知,这个占了buffer pool的大半空间 缓存目录--数据字典 insert buffer 排序的内部结构--比如自适应hash的结构或者一些行锁 1.buffer pool是怎样分配空间的? SELECT engine, count(*) as TABLES, concat(,),'M') rows, c…
先上效果图. 代码: <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"…