来自FallDream的博客,未经允许,请勿转载,谢谢。


跳蚤国有 n 个城市,伟大的跳蚤国王居住在跳蚤国首都中,即 1 号城市中。跳蚤国最大的问题就是饮水问题,由于首都中居住的跳蚤实在太多,跳蚤国王又体恤地将分配给他的水也给跳蚤国居民饮用,这导致跳蚤国王也经常喝不上水。于是,跳蚤国在每个城市都修建了一个圆柱形水箱,这些水箱完全相同且足够高。一个雨天后,第 i 个城市收集到了高度为 hi 的水。由于地理和天气因素的影响,任何两个不同城市收集到的水高度互不相同。跳蚤国王也请来蚂蚁工匠帮忙,建立了一个庞大的地下连通系统。跳蚤国王每次使用地下连通系统时,可以指定任意多的城市,将这些城市的水箱用地下连通系统连接起来足够长的时间之后,再将地下连通系统关闭。由连通器原理,这些城市的水箱中的水在这次操作后会到达同一高度,并且这一高度等于指定的各水箱高度的平均值。由于地下连通系统的复杂性,跳蚤国王至多只能使用 k 次地下连通系统。跳蚤国王请你告诉他,首都 1 号城市水箱中的水位最高能有多高?

n<=8000 hi<=10^5

至少保留p位小数 p<=3000

提供了一个高精度小数类

首先考虑只保留大于1号城市的高度,并且发现从小到大合并比较优秀 所以按照从小到大排序 求出前缀和Hi

然后每次都计算太麻烦了,所以用一个trick,先用long double计算出转移路径再计算答案 (题解里面一套分数类啥的可以直接做)

列出转移方程$f[k][i]=max(\frac{f[k-1][j]+si-sj}{i-j+1})$ 考虑维护(j-1,sj-f[k-1][j])的下凸壳,发现它满足决策单调性 于是复杂度降低至$O(n^{2}+np)$

但是根据题解里面一系列的结论,每次取的长度不同且递减,长度大于1的最多只有14个,所以先dp出14层,然后剩下的直接两两合并就行了。复杂度O(14n+np)

  1. // This is a test program with decimal lib
  2.  
  3. #include <cstdlib>
  4. #include <cstring>
  5. #include <string>
  6.  
  7. // ---------- decimal lib start ----------
  8.  
  9. const int PREC = ;
  10.  
  11. class Decimal {
  12. public:
  13. Decimal();
  14. Decimal(const std::string &s);
  15. Decimal(const char *s);
  16. Decimal(int x);
  17. Decimal(long long x);
  18. Decimal(double x);
  19.  
  20. bool is_zero() const;
  21.  
  22. // p (p > 0) is the number of digits after the decimal point
  23. std::string to_string(int p) const;
  24. double to_double() const;
  25.  
  26. friend Decimal operator + (const Decimal &a, const Decimal &b);
  27. friend Decimal operator + (const Decimal &a, int x);
  28. friend Decimal operator + (int x, const Decimal &a);
  29. friend Decimal operator + (const Decimal &a, long long x);
  30. friend Decimal operator + (long long x, const Decimal &a);
  31. friend Decimal operator + (const Decimal &a, double x);
  32. friend Decimal operator + (double x, const Decimal &a);
  33.  
  34. friend Decimal operator - (const Decimal &a, const Decimal &b);
  35. friend Decimal operator - (const Decimal &a, int x);
  36. friend Decimal operator - (int x, const Decimal &a);
  37. friend Decimal operator - (const Decimal &a, long long x);
  38. friend Decimal operator - (long long x, const Decimal &a);
  39. friend Decimal operator - (const Decimal &a, double x);
  40. friend Decimal operator - (double x, const Decimal &a);
  41.  
  42. friend Decimal operator * (const Decimal &a, int x);
  43. friend Decimal operator * (int x, const Decimal &a);
  44.  
  45. friend Decimal operator / (const Decimal &a, int x);
  46.  
  47. friend bool operator < (const Decimal &a, const Decimal &b);
  48. friend bool operator > (const Decimal &a, const Decimal &b);
  49. friend bool operator <= (const Decimal &a, const Decimal &b);
  50. friend bool operator >= (const Decimal &a, const Decimal &b);
  51. friend bool operator == (const Decimal &a, const Decimal &b);
  52. friend bool operator != (const Decimal &a, const Decimal &b);
  53.  
  54. Decimal & operator += (int x);
  55. Decimal & operator += (long long x);
  56. Decimal & operator += (double x);
  57. Decimal & operator += (const Decimal &b);
  58.  
  59. Decimal & operator -= (int x);
  60. Decimal & operator -= (long long x);
  61. Decimal & operator -= (double x);
  62. Decimal & operator -= (const Decimal &b);
  63.  
  64. Decimal & operator *= (int x);
  65.  
  66. Decimal & operator /= (int x);
  67.  
  68. friend Decimal operator - (const Decimal &a);
  69.  
  70. // These can't be called
  71. friend Decimal operator * (const Decimal &a, double x);
  72. friend Decimal operator * (double x, const Decimal &a);
  73. friend Decimal operator / (const Decimal &a, double x);
  74. Decimal & operator *= (double x);
  75. Decimal & operator /= (double x);
  76.  
  77. private:
  78. static const int len = ;
  79. static const int mo = ;
  80.  
  81. static void append_to_string(std::string &s, long long x);
  82.  
  83. bool is_neg;
  84. long long integer;
  85. int data[len];
  86.  
  87. void init_zero();
  88. void init(const char *s);
  89. };
  90.  
  91. Decimal::Decimal() {
  92. this->init_zero();
  93. }
  94.  
  95. Decimal::Decimal(const char *s) {
  96. this->init(s);
  97. }
  98.  
  99. Decimal::Decimal(const std::string &s) {
  100. this->init(s.c_str());
  101. }
  102.  
  103. Decimal::Decimal(int x) {
  104. this->init_zero();
  105.  
  106. if (x < ) {
  107. is_neg = true;
  108. x = -x;
  109. }
  110.  
  111. integer = x;
  112. }
  113.  
  114. Decimal::Decimal(long long x) {
  115. this->init_zero();
  116.  
  117. if (x < ) {
  118. is_neg = true;
  119. x = -x;
  120. }
  121.  
  122. integer = x;
  123. }
  124.  
  125. Decimal::Decimal(double x) {
  126. this->init_zero();
  127.  
  128. if (x < ) {
  129. is_neg = true;
  130. x = -x;
  131. }
  132.  
  133. integer = (long long)x;
  134. x -= integer;
  135.  
  136. for (int i = ; i < len; i++) {
  137. x *= mo;
  138. if (x < ) x = ;
  139. data[i] = (int)x;
  140. x -= data[i];
  141. }
  142. }
  143.  
  144. void Decimal::init_zero() {
  145. is_neg = false;
  146. integer = ;
  147. memset(data, , len * sizeof(int));
  148. }
  149.  
  150. bool Decimal::is_zero() const {
  151. if (integer) return false;
  152. for (int i = ; i < len; i++) {
  153. if (data[i]) return false;
  154. }
  155. return true;
  156. }
  157.  
  158. void Decimal::init(const char *s) {
  159. this->init_zero();
  160.  
  161. is_neg = false;
  162. integer = ;
  163.  
  164. // find the first digit or the negative sign
  165. while (*s != ) {
  166. if (*s == '-') {
  167. is_neg = true;
  168. ++s;
  169. break;
  170. } else if (*s >= && *s <= ) {
  171. break;
  172. }
  173. ++s;
  174. }
  175.  
  176. // read the integer part
  177. while (*s >= && *s <= ) {
  178. integer = integer * + *s - ;
  179. ++s;
  180. }
  181.  
  182. // read the decimal part
  183. if (*s == '.') {
  184. int pos = ;
  185. int x = mo / ;
  186.  
  187. ++s;
  188. while (pos < len && *s >= && *s <= ) {
  189. data[pos] += (*s - ) * x;
  190. ++s;
  191. x /= ;
  192. if (x == ) {
  193. ++pos;
  194. x = mo / ;
  195. }
  196. }
  197. }
  198. }
  199.  
  200. void Decimal::append_to_string(std::string &s, long long x) {
  201. if (x == ) {
  202. s.append(, );
  203. return;
  204. }
  205.  
  206. char _[];
  207. int cnt = ;
  208. while (x) {
  209. _[cnt++] = x % ;
  210. x /= ;
  211. }
  212. while (cnt--) {
  213. s.append(, _[cnt] + );
  214. }
  215. }
  216.  
  217. std::string Decimal::to_string(int p) const {
  218. std::string ret;
  219.  
  220. if (is_neg && !this->is_zero()) {
  221. ret = "-";
  222. }
  223.  
  224. append_to_string(ret, this->integer);
  225.  
  226. ret.append(, '.');
  227.  
  228. for (int i = ; i < len; i++) {
  229. // append data[i] as "%09d"
  230. int x = mo / ;
  231. int tmp = data[i];
  232. while (x) {
  233. ret.append(, + tmp / x);
  234. tmp %= x;
  235. x /= ;
  236. if (--p == ) {
  237. break;
  238. }
  239. }
  240. if (p == ) break;
  241. }
  242.  
  243. if (p > ) {
  244. ret.append(p, '');
  245. }
  246.  
  247. return ret;
  248. }
  249.  
  250. double Decimal::to_double() const {
  251. double ret = integer;
  252.  
  253. double k = 1.0;
  254. for (int i = ; i < len; i++) {
  255. k /= mo;
  256. ret += k * data[i];
  257. }
  258.  
  259. if (is_neg) {
  260. ret = -ret;
  261. }
  262.  
  263. return ret;
  264. }
  265.  
  266. bool operator < (const Decimal &a, const Decimal &b) {
  267. if (a.is_neg != b.is_neg) {
  268. return a.is_neg && (!a.is_zero() || !b.is_zero());
  269. } else if (!a.is_neg) {
  270. // a, b >= 0
  271. if (a.integer != b.integer) {
  272. return a.integer < b.integer;
  273. }
  274. for (int i = ; i < Decimal::len; i++) {
  275. if (a.data[i] != b.data[i]) {
  276. return a.data[i] < b.data[i];
  277. }
  278. }
  279. return false;
  280. } else {
  281. // a, b <= 0
  282. if (a.integer != b.integer) {
  283. return a.integer > b.integer;
  284. }
  285. for (int i = ; i < Decimal::len; i++) {
  286. if (a.data[i] != b.data[i]) {
  287. return a.data[i] > b.data[i];
  288. }
  289. }
  290. return false;
  291. }
  292. }
  293.  
  294. bool operator > (const Decimal &a, const Decimal &b) {
  295. if (a.is_neg != b.is_neg) {
  296. return !a.is_neg && (!a.is_zero() || !b.is_zero());
  297. } else if (!a.is_neg) {
  298. // a, b >= 0
  299. if (a.integer != b.integer) {
  300. return a.integer > b.integer;
  301. }
  302. for (int i = ; i < Decimal::len; i++) {
  303. if (a.data[i] != b.data[i]) {
  304. return a.data[i] > b.data[i];
  305. }
  306. }
  307. return false;
  308. } else {
  309. // a, b <= 0
  310. if (a.integer != b.integer) {
  311. return a.integer < b.integer;
  312. }
  313. for (int i = ; i < Decimal::len; i++) {
  314. if (a.data[i] != b.data[i]) {
  315. return a.data[i] < b.data[i];
  316. }
  317. }
  318. return false;
  319. }
  320. }
  321.  
  322. bool operator <= (const Decimal &a, const Decimal &b) {
  323. if (a.is_neg != b.is_neg) {
  324. return a.is_neg || (a.is_zero() && b.is_zero());
  325. } else if (!a.is_neg) {
  326. // a, b >= 0
  327. if (a.integer != b.integer) {
  328. return a.integer < b.integer;
  329. }
  330. for (int i = ; i < Decimal::len; i++) {
  331. if (a.data[i] != b.data[i]) {
  332. return a.data[i] < b.data[i];
  333. }
  334. }
  335. return true;
  336. } else {
  337. // a, b <= 0
  338. if (a.integer != b.integer) {
  339. return a.integer > b.integer;
  340. }
  341. for (int i = ; i < Decimal::len; i++) {
  342. if (a.data[i] != b.data[i]) {
  343. return a.data[i] > b.data[i];
  344. }
  345. }
  346. return true;
  347. }
  348. }
  349.  
  350. bool operator >= (const Decimal &a, const Decimal &b) {
  351. if (a.is_neg != b.is_neg) {
  352. return !a.is_neg || (a.is_zero() && b.is_zero());
  353. } else if (!a.is_neg) {
  354. // a, b >= 0
  355. if (a.integer != b.integer) {
  356. return a.integer > b.integer;
  357. }
  358. for (int i = ; i < Decimal::len; i++) {
  359. if (a.data[i] != b.data[i]) {
  360. return a.data[i] > b.data[i];
  361. }
  362. }
  363. return true;
  364. } else {
  365. // a, b <= 0
  366. if (a.integer != b.integer) {
  367. return a.integer < b.integer;
  368. }
  369. for (int i = ; i < Decimal::len; i++) {
  370. if (a.data[i] != b.data[i]) {
  371. return a.data[i] < b.data[i];
  372. }
  373. }
  374. return true;
  375. }
  376. }
  377.  
  378. bool operator == (const Decimal &a, const Decimal &b) {
  379. if (a.is_zero() && b.is_zero()) return true;
  380. if (a.is_neg != b.is_neg) return false;
  381. if (a.integer != b.integer) return false;
  382. for (int i = ; i < Decimal::len; i++) {
  383. if (a.data[i] != b.data[i]) return false;
  384. }
  385. return true;
  386. }
  387.  
  388. bool operator != (const Decimal &a, const Decimal &b) {
  389. return !(a == b);
  390. }
  391.  
  392. Decimal & Decimal::operator += (long long x) {
  393. if (!is_neg) {
  394. if (integer + x >= ) {
  395. integer += x;
  396. } else {
  397. bool last = false;
  398. for (int i = len - ; i >= ; i--) {
  399. if (last || data[i]) {
  400. data[i] = mo - data[i] - last;
  401. last = true;
  402. } else {
  403. last = false;
  404. }
  405. }
  406. integer = -x - integer - last;
  407. is_neg = true;
  408. }
  409. } else {
  410. if (integer - x >= ) {
  411. integer -= x;
  412. } else {
  413. bool last = false;
  414. for (int i = len - ; i >= ; i--) {
  415. if (last || data[i]) {
  416. data[i] = mo - data[i] - last;
  417. last = true;
  418. } else {
  419. last = false;
  420. }
  421. }
  422. integer = x - integer - last;
  423. is_neg = false;
  424. }
  425. }
  426. return *this;
  427. }
  428.  
  429. Decimal & Decimal::operator += (int x) {
  430. return *this += (long long)x;
  431. }
  432.  
  433. Decimal & Decimal::operator -= (int x) {
  434. return *this += (long long)-x;
  435. }
  436.  
  437. Decimal & Decimal::operator -= (long long x) {
  438. return *this += -x;
  439. }
  440.  
  441. Decimal & Decimal::operator /= (int x) {
  442. if (x < ) {
  443. is_neg ^= ;
  444. x = -x;
  445. }
  446.  
  447. int last = integer % x;
  448. integer /= x;
  449.  
  450. for (int i = ; i < len; i++) {
  451. long long tmp = 1LL * last * mo + data[i];
  452. data[i] = tmp / x;
  453. last = tmp - 1LL * data[i] * x;
  454. }
  455.  
  456. if (is_neg && integer == ) {
  457. int i;
  458. for (i = ; i < len; i++) {
  459. if (data[i] != ) {
  460. break;
  461. }
  462. }
  463. if (i == len) {
  464. is_neg = false;
  465. }
  466. }
  467.  
  468. return *this;
  469. }
  470.  
  471. Decimal & Decimal::operator *= (int x) {
  472. if (x < ) {
  473. is_neg ^= ;
  474. x = -x;
  475. } else if (x == ) {
  476. init_zero();
  477. return *this;
  478. }
  479.  
  480. int last = ;
  481. for (int i = len - ; i >= ; i--) {
  482. long long tmp = 1LL * data[i] * x + last;
  483. last = tmp / mo;
  484. data[i] = tmp - 1LL * last * mo;
  485. }
  486. integer = integer * x + last;
  487.  
  488. return *this;
  489. }
  490.  
  491. Decimal operator - (const Decimal &a) {
  492. Decimal ret = a;
  493. // -0 = 0
  494. if (!ret.is_neg && ret.integer == ) {
  495. int i;
  496. for (i = ; i < Decimal::len; i++) {
  497. if (ret.data[i] != ) break;
  498. }
  499. if (i < Decimal::len) {
  500. ret.is_neg = true;
  501. }
  502. } else {
  503. ret.is_neg ^= ;
  504. }
  505. return ret;
  506. }
  507.  
  508. Decimal operator + (const Decimal &a, int x) {
  509. Decimal ret = a;
  510. return ret += x;
  511. }
  512.  
  513. Decimal operator + (int x, const Decimal &a) {
  514. Decimal ret = a;
  515. return ret += x;
  516. }
  517.  
  518. Decimal operator + (const Decimal &a, long long x) {
  519. Decimal ret = a;
  520. return ret += x;
  521. }
  522.  
  523. Decimal operator + (long long x, const Decimal &a) {
  524. Decimal ret = a;
  525. return ret += x;
  526. }
  527.  
  528. Decimal operator - (const Decimal &a, int x) {
  529. Decimal ret = a;
  530. return ret -= x;
  531. }
  532.  
  533. Decimal operator - (int x, const Decimal &a) {
  534. return -(a - x);
  535. }
  536.  
  537. Decimal operator - (const Decimal &a, long long x) {
  538. Decimal ret = a;
  539. return ret -= x;
  540. }
  541.  
  542. Decimal operator - (long long x, const Decimal &a) {
  543. return -(a - x);
  544. }
  545.  
  546. Decimal operator * (const Decimal &a, int x) {
  547. Decimal ret = a;
  548. return ret *= x;
  549. }
  550.  
  551. Decimal operator * (int x, const Decimal &a) {
  552. Decimal ret = a;
  553. return ret *= x;
  554. }
  555.  
  556. Decimal operator / (const Decimal &a, int x) {
  557. Decimal ret = a;
  558. return ret /= x;
  559. }
  560.  
  561. Decimal operator + (const Decimal &a, const Decimal &b) {
  562. if (a.is_neg == b.is_neg) {
  563. Decimal ret = a;
  564. bool last = false;
  565. for (int i = Decimal::len - ; i >= ; i--) {
  566. ret.data[i] += b.data[i] + last;
  567. if (ret.data[i] >= Decimal::mo) {
  568. ret.data[i] -= Decimal::mo;
  569. last = true;
  570. } else {
  571. last = false;
  572. }
  573. }
  574. ret.integer += b.integer + last;
  575. return ret;
  576. } else if (!a.is_neg) {
  577. // a - |b|
  578. return a - -b;
  579. } else {
  580. // b - |a|
  581. return b - -a;
  582. }
  583. }
  584.  
  585. Decimal operator - (const Decimal &a, const Decimal &b) {
  586. if (!a.is_neg && !b.is_neg) {
  587. if (a >= b) {
  588. Decimal ret = a;
  589. bool last = false;
  590. for (int i = Decimal::len - ; i >= ; i--) {
  591. ret.data[i] -= b.data[i] + last;
  592. if (ret.data[i] < ) {
  593. ret.data[i] += Decimal::mo;
  594. last = true;
  595. } else {
  596. last = false;
  597. }
  598. }
  599. ret.integer -= b.integer + last;
  600. return ret;
  601. } else {
  602. Decimal ret = b;
  603. bool last = false;
  604. for (int i = Decimal::len - ; i >= ; i--) {
  605. ret.data[i] -= a.data[i] + last;
  606. if (ret.data[i] < ) {
  607. ret.data[i] += Decimal::mo;
  608. last = true;
  609. } else {
  610. last = false;
  611. }
  612. }
  613. ret.integer -= a.integer + last;
  614. ret.is_neg = true;
  615. return ret;
  616. }
  617. } else if (a.is_neg && b.is_neg) {
  618. // a - b = (-b) - (-a)
  619. return -b - -a;
  620. } else if (a.is_neg) {
  621. // -|a| - b
  622. return -(-a + b);
  623. } else {
  624. // a - -|b|
  625. return a + -b;
  626. }
  627. }
  628.  
  629. Decimal operator + (const Decimal &a, double x) {
  630. return a + Decimal(x);
  631. }
  632.  
  633. Decimal operator + (double x, const Decimal &a) {
  634. return Decimal(x) + a;
  635. }
  636.  
  637. Decimal operator - (const Decimal &a, double x) {
  638. return a - Decimal(x);
  639. }
  640.  
  641. Decimal operator - (double x, const Decimal &a) {
  642. return Decimal(x) - a;
  643. }
  644.  
  645. Decimal & Decimal::operator += (double x) {
  646. *this = *this + Decimal(x);
  647. return *this;
  648. }
  649.  
  650. Decimal & Decimal::operator -= (double x) {
  651. *this = *this - Decimal(x);
  652. return *this;
  653. }
  654.  
  655. Decimal & Decimal::operator += (const Decimal &b) {
  656. *this = *this + b;
  657. return *this;
  658. }
  659.  
  660. Decimal & Decimal::operator -= (const Decimal &b) {
  661. *this = *this - b;
  662. return *this;
  663. }
  664.  
  665. // ---------- decimal lib end ----------
  666. #include<cstdio>
  667. #include<iostream>
  668. #include<algorithm>
  669. using namespace std;
  670.  
  671. #define MN 8000
  672. #define ld long double
  673.  
  674. inline int read()
  675. {
  676. int x = , f = ; char ch = getchar();
  677. while(ch < '' || ch > ''){ if(ch == '-') f = -; ch = getchar();}
  678. while(ch >= '' && ch <= ''){x = x * + ch - '';ch = getchar();}
  679. return x * f;
  680. }
  681. int n , m , k , K , p , h[MN + ] , Pre , top , From[][MN + ];
  682. ld f[][MN + ];
  683. struct P
  684. {
  685. int x; ld y;
  686. P(int _x = ,ld _y = ): x(_x) , y(_y) {}
  687. friend ld Calc(P a , P b)
  688. {
  689. return (b.y - a.y) / (b.x - a.x);
  690. }
  691. };
  692.  
  693. struct MyQueue
  694. {
  695. P q[MN + ];int top , tail;
  696. void Clear(){ q[top = tail = ] = P( - , -Pre);}
  697. void ins(P t)
  698. {
  699. while(top > tail && Calc(q[top-] , q[top]) > Calc(q[top] , t)) --top;
  700. q[ ++top ] = t;
  701. }
  702. int Query(P t)
  703. {
  704. while(top > tail && Calc(q[tail] , t) < Calc(q[tail + ] , t)) ++tail;
  705. return q[tail].x + ;
  706. }
  707. }Q;
  708.  
  709. Decimal Ans;
  710.  
  711. void Dfs(int t , int x)
  712. {
  713. if(!t) return;
  714. Dfs( t - , From[t][x] );
  715. Ans = ( Ans + h[x] - h[From[t][x]] ) / (x - From[t][x] + );
  716. }
  717.  
  718. int main() {
  719. m = read(); K = read(); p = read(); Pre = read();
  720. for(int i = , j;i < m ;++i)
  721. if((j = read()) > Pre) h[++n] = j;
  722. sort(h+ , h + n + ); K = min(K , n); k = min(K , );
  723. for(int i = ;i <= n ;++i) h[i] += h[i-] , f[][i] = Pre;h[] = -Pre;
  724. for(int j = ;j <= k ;++j)
  725. {
  726. Q.Clear();
  727. for(int i = ;i <= n ; ++i)
  728. {
  729. From[j][i] = Q.Query(P(i , h[i]));
  730. f[j][i] = (f[j - ][From[j][i]] + h[i] - h[ From[j][i] ]) / (i - From[j][i] + );
  731. Q.ins(P(i - , h[i] - f[j - ][i]));
  732. }
  733. }
  734. Ans = Decimal ( Pre ); h[] = ;
  735. Dfs ( k , n - (K - k) );
  736. for(int i = n - (K - k) + ;i <= n ; ++i) Ans = (Ans + h[i] - h[i-]) / ;
  737. cout << Ans.to_string(p + );
  738. return ;
  739. }

[Noi2016]国王饮水记的更多相关文章

  1. [UOJ#223][BZOJ4654][Noi2016]国王饮水记

    [UOJ#223][BZOJ4654][Noi2016]国王饮水记 试题描述 跳蚤国有 n 个城市,伟大的跳蚤国王居住在跳蚤国首都中,即 1 号城市中.跳蚤国最大的问题就是饮水问题,由于首都中居住的跳 ...

  2. luogu P1721 [NOI2016]国王饮水记 斜率优化dp 贪心 决策单调性

    LINK:国王饮水记 看起来很不可做的样子. 但实际上还是需要先考虑贪心. 当k==1的时候 只有一次操作机会.显然可以把那些比第一个位置小的都给扔掉. 然后可以得知剩下序列中的最大值一定会被选择. ...

  3. BZOJ4654/UOJ223 [Noi2016]国王饮水记

    本文版权归ljh2000和博客园共有,欢迎转载,但须保留此声明,并给出原文链接,谢谢合作. 本文作者:ljh2000 作者博客:http://www.cnblogs.com/ljh2000-jump/ ...

  4. uoj233/BZOJ4654/洛谷P1721 [Noi2016]国王饮水记 【dp + 斜率优化】

    题目链接 uoj233 题解 下面不加证明地给出几个性质: 小于\(h[1]\)的城市一定是没用的 任何城市联通包含\(1\)且只和\(1\)联通一次 联通顺序从小到大最优 单个联通比多个一起联通要优 ...

  5. BZOJ4654 NOI2016国王饮水记(动态规划+三分)

    有很多比较显然的性质.首先每个城市(除1外)至多被连通一次,否则没有意义.其次将城市按水位从大到小排序后,用以连通的城市集合是一段前缀,并且不应存在比1城市还小的.然后如果确定了选取的城市集合,每次选 ...

  6. P1721 [NOI2016] 国王饮水记 题解

    蒟蒻的第一篇黑题题解,求过. 题目链接 题意描述 这道题用简洁的话来说,就是: 给你 \(n\) 个数字,你可以让取其中任意若干个数字,每次操作,都会使所有取的数字变为取的数字的平均数,并且你最多只能 ...

  7. 【BZOJ4654】【NOI2016】国王饮水记(动态规划,斜率优化)

    [BZOJ4654][NOI2016]国王饮水记(动态规划,斜率优化) 题面 BZOJ 洛谷 题解 首先肯定是找性质. 明确一点,比\(h_1\)小的没有任何意义. 所以我们按照\(h\)排序,那么\ ...

  8. *UOJ#223. 【NOI2016】国王饮水记

    $n \leq 8000$的数列,问不超过$m \leq 1e9$次操作后第一个数字最大是多少.操作:选一些数,把他们变成他们的平均值.需要保留$p \leq 3000$位小数,提供了一个小数高精度库 ...

  9. [NOI 2016]国王饮水记

    Description 题库链接 给出 \(n\) 个水杯,每个水杯装有不同高度的水 \(h_i\) ,每次可以指定任意多水杯用连通器连通后断开,问不超过 \(k\) 次操作之后 \(1\) 号水杯的 ...

随机推荐

  1. Angular组件——组件生命周期(一)

    组件声明周期以及angular的变化发现机制 红色方法只执行一次. 变更检测执行的绿色方法和和组件初始化阶段执行的绿色方法是一个方法. 总共9个方法. 每个钩子都是@angular/core库里定义的 ...

  2. vue 的模板编译—ast(抽象语法树) 详解与实现

    首先AST是什么? 在计算机科学中,抽象语法树(abstract syntax tree或者缩写为AST),或者语法树(syntax tree),是源代码的抽象语法结构的树状表现形式,这里特指编程语言 ...

  3. Faster R-CNN 的 RPN 是啥子?

     Faster R-CNN,由两个模块组成: 第一个模块是深度全卷积网络 RPN,用于 region proposal; 第二个模块是Fast R-CNN检测器,它使用了RPN产生的region p ...

  4. excel2003和excel2007文件的创建和读取

    excel2003和excel2007文件的创建和读取在项目中用的很多,首先我们要了解excel的常用组件和基本操作步骤. 常用组件如下所示: HSSFWorkbook excel的文档对象 HSSF ...

  5. ES6常用新特性

    https://segmentfault.com/a/1190000011976770?share_user=1030000010776722 该文章为转载文章!仅个人喜好收藏文章! 1.前言 前几天 ...

  6. 再一次, 不要使用(include/require)_once

    本文地址: http://www.laruence.com/2012/09/12/2765.html 最近关于apc.include_once_override的去留, 我们做了几次讨论, 这个APC ...

  7. xxe漏洞检测及代码执行过程

    这两天看了xxe漏洞,写一下自己的理解,xxe漏洞主要针对webservice危险的引用的外部实体并且未对外部实体进行敏感字符的过滤,从而可以造成命令执行,目録遍历等.首先存在漏洞的web服务一定是存 ...

  8. Vue2学习小记-给Vue2路由导航钩子和axios拦截器做个封装

    1.写在前面 最近在学习Vue2,遇到有些页面请求数据需要用户登录权限.服务器响应不符预期的问题,但是总不能每个页面都做单独处理吧,于是想到axios提供了拦截器这个好东西,再于是就出现了本文. 2. ...

  9. kubernetes入门(01)kubernetes是什么?

    一.kubernetes是什么? Kubernetes是Google开源的一个容器编排引擎,它支持自动化部署.大规模可伸缩.应用容器化管理.在生产环境中部署一个应用程序时,通常要部署该应用的多个实例以 ...

  10. 新概念英语(1-59)Is that all

    Does the lady buy any chalk? A:I want some envelopes, please. B:Do you want the large size or the sm ...