POJ 2188 Cow Laundry
Cow Laundry Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 1376 Accepted: 886 Description
The cows have erected clothes lines with N (1 <= N <= 1000) wires upon which they can dry their clothes after washing them. Having no opposable thumbs, they have thoroughly botched the job. Consider this clothes line arrangement with four wires:
Wire slot: 1 2 3 4
--------------- <-- the holder of the wires
/ /
/ /
/ /
/ / <-- actual clothes lines
/
/ /
/ /
/ /
/ /
--------------- <-- the holder of the wires
Wire slot: 1 2 3 4
The wires cross! This is, of course, unacceptable.
The cows want to unscramble the clothes lines with a minimum of hassle. Even their bovine minds can handle the notion of “swap these two lines”. Since the cows have short arms they are limited to swapping adjacent pairs of wire endpoints on either the top or bottom holder. In the diagram above, it requires four such swaps in order to get a proper arrangement for the clothes line:
1 2 3 4
------------- <-- the holder of the wires
| | | |
| | | |
| | | |
| | | |
| | | |
| | | |
| | | |
| | | |
| | | |
------------- <-- the holder of the wires
1 2 3 4
Help the cows unscramble their clothes lines. Find the smallest number of swaps that will get the clothes line into a proper arrangement.
You are supplied with clothes line descriptions that use integers to describe the current ordering of the clothesline. The lines are uniquely numbered 1…N according to no apparent scheme. You are given the order of the wires as they appear in the N connecting slots of the top wire holder and also the order of the wires as they appear on the bottom wire holder. Input
- Line 1: A single integer: N
- Lines 2…N+1: Each line contains two integers in the range 1…N. The first integer is the wire ID of the wire in the top wire holder; the second integer is the wire ID of the wire in the bottom holder. Line 2 describes the wires connected to top slot 1 and bottom slot 1, respectively; line 3 describes the wires connected to top and bottom slot 2, respectively; and so on.
Output
- Line 1: A single integer specifying the minimum number of adjacent swaps required to straighten out the clothes lines. Sample Input
4 4 1 2 3 1 4 3 2 Sample Output
4 Source
USACO 2003 Fall Orange
找到规律的话就是求有多少逆序对,还是比较好想的,但是要处理的话,这个逆序是相对于开始状态,不是另一端点,代码比较简单,思维题,签到题)
#include<iostream>
#include<map>
using namespace std;
int ob[1005];
int oj[1005];
map<int,int>w;
int main()
{
int n;
w.clear();
cin>>n;
for(int i=0;i<n;i++){
cin>>ob[i]>>oj[i];
w.insert(make_pair(ob[i],i));
}
int ans=0;
for(int i=0;i<n;i++)
for(int j=i+1;j<n;j++)
if(w[oj[i]]>w[oj[j]]) ans++;
cout<<ans<<endl;
}
- JavaScript 教程
- JavaScript 编辑工具
- JavaScript 与HTML
- JavaScript 与Java
- JavaScript 数据结构
- JavaScript 基本数据类型
- JavaScript 特殊数据类型
- JavaScript 运算符
- JavaScript typeof 运算符
- JavaScript 表达式
- JavaScript 类型转换
- JavaScript 基本语法
- JavaScript 注释
- Javascript 基本处理流程
- Javascript 选择结构
- Javascript if 语句
- Javascript if 语句的嵌套
- Javascript switch 语句
- Javascript 循环结构
- Javascript 循环结构实例
- Javascript 跳转语句
- Javascript 控制语句总结
- Javascript 函数介绍
- Javascript 函数的定义
- Javascript 函数调用
- Javascript 几种特殊的函数
- JavaScript 内置函数简介
- Javascript eval() 函数
- Javascript isFinite() 函数
- Javascript isNaN() 函数
- parseInt() 与 parseFloat()
- escape() 与 unescape()
- Javascript 字符串介绍
- Javascript length属性
- javascript 字符串函数
- Javascript 日期对象简介
- Javascript 日期对象用途
- Date 对象属性和方法
- Javascript 数组是什么
- Javascript 创建数组
- Javascript 数组赋值与取值
- Javascript 数组属性和方法
- kettle学习笔记(六)——kettle转换步骤
- 记一次带层级结构列表数据计算性能优化
- kettle学习笔记(九)——子转换、集群与变量
- Activiti5工作流笔记一
- Activiti5工作流笔记二
- Activiti5工作流笔记三
- 短信验证码“最佳实践”
- 最近的项目系列1——core整合SPA
- 最近的项目系之2——core3.0整合Autofac
- 最近的项目系之3——core3.0整合Senparc
- 使用bat执行java项目
- Core + Vue 后台管理基础框架2——认证
- Core + Vue 后台管理基础框架3——后端授权
- Core + Vue 后台管理基础框架4——前端授权
- ent orm笔记4---Code Generation