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

太长懒得写了。。总之就是个斜率优化DP,然后有奇怪性质

原题解

基本能猜到定理八,十至今没理解QAQ

用前八个定理写了一份被卡精度的代码。就是DP的时候记决策点,然后最后用决策点算答案即可。但DP过程本身精度损得厉害,所以有些点过不了。

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

*UOJ#223. 【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. [Noi2016]国王饮水记

    来自FallDream的博客,未经允许,请勿转载,谢谢. 跳蚤国有 n 个城市,伟大的跳蚤国王居住在跳蚤国首都中,即 1 号城市中.跳蚤国最大的问题就是饮水问题,由于首都中居住的跳蚤实在太多,跳蚤国王 ...

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

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

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

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

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

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

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

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

  9. [NOI 2016]国王饮水记

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

随机推荐

  1. 51nod——2476 小b和序列(预处理 思维)

    对于每一个元素,预处理出它作为最小值,两边可以作用到的最大位置.比如下标∈[0,8]的这个数组:1 8 6 2 5 4 3 8 7,1可以作用到所有区间,2可以作用到区间[1,8],第一个8可以作用到 ...

  2. 1045: [HAOI2008] 糖果传递

    Time Limit: 10 Sec  Memory Limit: 162 MBSubmit: 4897  Solved: 2457[Submit][Status][Discuss] Descript ...

  3. js函数带括号和不带括号赋给对象属性的区别

    注意: 1.js为对象添加函数时,不要在函数后面加().一旦加了括号是表示将函数的返回值赋给对象的属性. 例:function test(){ document.writeln("我是js函 ...

  4. php扩展开发-实现一个简易的哈希表

    从一个简易的哈希表入手,会让你更好的理解php的哈希表,他们的本质是一样的,只是php的哈希表做了更多的功能扩展,php的哈希表是php语言的一个重要核心,大量的内核代码使用到哈希表. #includ ...

  5. Ubuntu12.04下YouCompleteMe安装教程(部分)

    1.通过源码编译安装VIM 开发中使用的是Ubuntu 12.04 LTS,通过sudo apt-get install vim安装的版本较低,不支持YCM,所以,用源码编译并安装最新的Vim. 卸载 ...

  6. linux安装vmware出现kernel-header问题

    查看日志文件, cat /tmp/vmware-xiuyuan/vmware-modconfig-9996.log | more在日志文件中有这么几行:Setting header path for ...

  7. 使用Hbase快照将数据输出到互联网区测试环境的临时Hbase集群

    通过snapshot对内网测试环境Hbase生产集群的全量数据(包括原始数据和治理后数据)复制到互联网Hbase临时集群.工具及原理: 1)         Hbase自带镜像导出工具(snapsho ...

  8. HDU1301 Jungle Roads

    Jungle Roads The Head Elder of the tropical island of Lagrishan has a problem. A burst of foreign ai ...

  9. python资源大全2

    原文链接 网络 Scapy, Scapy3k: 发送,嗅探,分析和伪造网络数据包.可用作交互式包处理程序或单独作为一个库. pypcap, Pcapy, pylibpcap: 几个不同 libpcap ...

  10. 笔记-算法-KMP算法

    笔记-算法-KMP算法 1.      KMP算法 KMP算法是一种改进的字符串匹配算法,KMP算法的关键是利用匹配失败后的信息,尽量减少模式串与主串的匹配次数以达到快速匹配的目的.具体实现就是实现一 ...