c语言sscanf函数的用法是什么
285
2022-09-02
bzoj1520 [POI2006]Szk-Schools
( 题目描述
There are nn
n schools in Byteotia, and each has its number mm
m, 1≤m≤n1\le m\le n
1≤m≤n, just as every school tends to. However, the previous king of Byteotia paid little attention to the school numbering, and generously allowed every new school to choose any number from the range 1⋯n1\cdots n
1⋯n. There is thus no guarantee that the numbers are unique, in fact it seems highly unlikely. Clearly some schools may have chosen the same number, and as a consequence some numbers from the range 1⋯n1\cdots n
1⋯n might be not used at all. A perfect numbering would be a permutation, i.e. a one that assigns each number from the specified range to exactly one school.
The newly crowned king of Byteotia wants to reform the numbering system, so that every number would be used exactly once. It is, however, not an easy task, since most schools are reluctant to change the numbers they have once chosen.
The king has sent his most trusted informants to all the schools to inquire which numbers each school would accept. Since every school would like to keep its current number (or at least a number close to it), each school director has specified an interval containing the school’s current number. These intervals are called the tolerance intervals. Furthermore, each school has stated the cost cc
c of changing its number by 11
Hence the total cost of changing a school’s number equalsc×∣m−m′∣c\times|m-m’|
c×∣m−m′∣, where mm
m denotes the old school number, and m′m’
m′ the new one. Of course m′m’
m′ must lie in the tolerance interval previously specified by the school. Now, all the information gathered, the king would like to know, if it’s possible to introduce a perfect numbering (while complying with every school’s tolerance interval), and if so, what is the minimal cost of such reenumaration. He has asked you - the royal computer scientist - to carefully study the information he has provided you with and give the answer in return.
TaskWrite a programme which:
reads from the standard input the current numbers of Byteotian schools, their tolerance intervals and the costs of changing their numbers by ,checks if it’s possible to perfectly reenumerate the schools complying with all previously described conditions, and if so, determines the minimal cost of such reenumeration,writes the result to the standard output.
有n间学校,每个学校都有自己的数字m, 1 <=m <= n.因为以前 的国王疏于管理,所以准许每间新学校从1- n任意的选数字.所以并不能保证 所有学校的数字都唯一.一个充美的标号应该每个学校都有一个唯一的数字, 即他们是一个1- n的排列.新的国王想改革数字系统,他想使学校标号成为一个 完美标号,但这并不是一个简单的工作,因为大多数的学较非常不情愿改变他们 曾经选择的标号.国王派出了他最信任的助手到学校去询问每个学校能接受哪些 标号.因为每个学校都想尽量保持自己原有标号(或者是一个尽量和其接近的标 号),所以每个学校都给出了一个它能接受的标号区间.这些区间称为可忍受区 间.此外,每个学校都给出了一个整数c表示将编号改变1的代价.所以一个学校的总的改变代价应该为c|m-m’|,这里的m是学校的老编号,m’为新编号. 当然W必须包含在可忍受区间之内.现在国王己经知道了所有的信息,他想知道 将卑梭编号改变为完美标号的最小代价.当不能满足所有条件时输出NIE 输入输出格式
输入格式: The first line of the standard input contains one integer nn
n ( 1≤n≤2001\le n\le 200
1≤n≤200), denoting the number of schools in Byteotia. In the following nn
n lines there are descriptions of the schools themselves. The line no. i+1i+1
i+1 ( 1≤i≤n1\le i\le n
1≤i≤n) contains four integers mim_i
mi, aia_i
ai, bib_i
bi and kik_i
ki ( 1≤ai≤mi≤bi≤n1\le a_i\le m_i\le b_i\le n
1≤ai≤mi≤bi≤n, 1≤ki≤1 0001\le k_i\le 1\ 000
1≤ki≤1 000), separated by single spaces. These denote respectively: the current number of the ii
i’th school, the left and right endpoint of the ii
i’th school’s tolerance interval regarding the change of number (it is a closed interval, therefore the new ii
i’th school’s number mi′m’_i
mi′ must satisfy the inequality ai≤mi′≤bia_i\le m’_i\le b_i
ai≤mi′≤bi) and the cost of changing the number of ii
i’th school by 11
1.
输出格式: If a reenumeration satisfying the above conditions is possible, the programme should write one integer kk
k denoting the minimum possible cost of performing the operation. If it’s not possible, it should write the word NIE, which means no in Polish. 输入输出样例
输入样例#1: 复制
5 1 1 2 3 1 1 5 1 3 2 5 5 4 1 5 10 3 3 3 1
输出样例#1: 复制
9
费用流裸题吧
学校看成1~N的点 新的编号看成1~n的点 然后给每个学校都去向新的编号区间连边即可
费用就是 c*(标号之差) 跑一下费用流
#include
版权声明:本文内容由网络用户投稿,版权归原作者所有,本站不拥有其著作权,亦不承担相应法律责任。如果您发现本站中有涉嫌抄袭或描述失实的内容,请联系我们jiasou666@gmail.com 处理,核实后本网站将在24小时内删除侵权内容。
发表评论
暂时没有评论,来抢沙发吧~