poj 1759 Garland】的更多相关文章

POJ 1759 Garland  这个题wa了27次,忘了用一个数来储存f[n-1],每次由于二分都会改变f[n-1]的值,得到的有的值不精确,直接输出f[n-1]肯定有问题. 这个题用c++交可以过,g++交过不了, f[i]=2+2*f[i-1]-f[i-2]; f[0]=A,f[1]=x; 二分枚举x的值,最终得到B的值(不是f[n-1]), 上述递推式是非齐次的二阶递推式,解其齐次特征方程,可以得到f[n-1]的齐次时的表达式,对于非齐次的,目前我还没法求出通式, B与f[n-1]的关…
[题目链接] http://poj.org/problem?id=1759 [题目大意] 有n个数字H,H[i]=(H[i-1]+H[i+1])/2-1,已知H[1],求最大H[n], 使得所有的H均大于0. [题解] 我们得到递推式子H[i]=2*H[i-1]+2-H[i-2],发现H[n]和H[2]成正相关 所以我们只要二分H[2]的取值,同时计算每个H是否大于等于0即可. [代码] #include <cstdio> int n; double H[1010],A,B; bool che…
Garland Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 2365   Accepted: 1007 Description The New Year garland consists of N lamps attached to a common wire that hangs down on the ends to which outermost lamps are affixed. The wire sags…
Description The New Year garland consists of N lamps attached to a common wire that hangs down on the ends to which outermost lamps are affixed. The wire sags under the weight of lamp millimeter lower than the average height of the two adjacent lamps…
 挂彩灯 题目大意:就是要布场的时候需要挂彩灯,彩灯挂的高度满足: H1 = A Hi = (Hi-1 + Hi+1)/2 - 1, for all 1 < i < N HN = B Hi >= 0, for all 1 <= i <= N 现在已知彩灯的个数和第一个彩灯挂的高度,要你求最后一个彩灯最低能挂多高? 这又是个最大化最小值的问题,从题目中我们可以看到递推公式的影子,其实这一题我们只要把答案二分,然后根据递推公式写出通项公式,一个灯一个灯看是否有低于0的高度就好 递…
Garland Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 1236   Accepted: 547 Description The New Year garland consists of N lamps attached to a common wire that hangs down on the ends to which outermost lamps are affixed. The wire sags u…
传送门:Problem 1759 https://www.cnblogs.com/violet-acmer/p/9793209.html 题意: 有N个彩灯关在同一条绳上,给出第一个彩灯的高度A,并给出求解其他彩灯的公式 h[i]=(h[i-1]+h[i+1])/2-1; 求最后一个彩灯的最低高度,并且保证所有的彩灯都不会着地. 题解: 二分第二个彩灯的高度h[2],h[2]越小,h[N]就越小. 证明: 假设最低的彩灯为 i. 由公式可得 h[2] = (h[1]+h[3])/2-1; 有了前…
题意:N个等差数列,初项X_i,末项Y_i,公差Z_i,求出现奇数次的数? 思路: 因为只有一个数出现的次数为奇数个 假设 第二个数字的个数为 奇数个,其余全部都是偶数个 ,累计出现的次数 a1偶数 a1+a2 奇数 a1+a2+a3 奇数 ................... 会出现这种情况:偶偶偶...偶奇 第一个出现奇的就是我们想要的 解决问题的代码: #include <iostream> #include <stdio.h> #include <algorithm…
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…
POJ 1064 题意 有N条绳子,它们长度分别为Li.如果从它们中切割出K条长度相同的绳子的话,这K条绳子每条最长能有多长?答案保留小数点后2位. 思路 二分搜索.这里要注意精度问题,代码中有详细说明:还有printf的%.2f会四舍五入的,需要*100再取整以截取小数点后两位. #include<stdio.h> #include<string.h> #include<string> #include<iostream> #include<math…
题目链接:http://poj.org/problem?id=1759 Garland Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 2477   Accepted: 1054 Description The New Year garland consists of N lamps attached to a common wire that hangs down on the ends to which outermo…
poj 题目分类 按照ac的代码长度分类(主要参考最短代码和自己写的代码) 短代码:0.01K--0.50K:中短代码:0.51K--1.00K:中等代码量:1.01K--2.00K:长代码:2.01K以上. 短:1147.1163.1922.2211.2215.2229.2232.2234.2242.2245.2262.2301.2309.2313.2334.2346.2348.2350.2352.2381.2405.2406: 中短:1014.1281.1618.1928.1961.2054…
本文来自:http://www.cppblog.com/snowshine09/archive/2011/08/02/152272.spx 多版本的POJ分类 流传最广的一种分类: 初期: 一.基本算法: (1)枚举. (poj1753,poj2965) (2)贪心(poj1328,poj2109,poj2586) (3)递归和分治法. (4)递推. (5)构造法.(poj3295) (6)模拟法.(poj1068,poj2632,poj1573,poj2993,poj2996) 二.图算法:…
acm之pku题目分类 对ACM有兴趣的同学们可以看看 DP:  1011   NTA                 简单题  1013   Great Equipment     简单题  1024   Calendar Game       简单题  1027   Human Gene Functions   简单题  1037   Gridland            简单题  1052   Algernon s Noxious Emissions 简单题  1409   Commun…
转载:from: POJ:http://blog.csdn.net/qq_28236309/article/details/47818407 按照ac的代码长度分类(主要参考最短代码和自己写的代码) 短代码:0.01K–0.50K:中短代码:0.51K–1.00K:中等代码量:1.01K–2.00K:长代码:2.01K以上. 短:1147.1163.1922.2211.2215.2229.2232.2234.2242.2245.2262.2301.2309.2313.2334.2346.2348…
Halloween treats Time Limit: 2000MS   Memory Limit: 65536K Total Submissions: 7644   Accepted: 2798   Special Judge Description Every year there is the same problem at Halloween: Each neighbour is only willing to give a certain total number of sweets…
Find a multiple Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 7192   Accepted: 3138   Special Judge Description The input contains N natural (i.e. positive integer) numbers ( N <= 10000 ). Each of that numbers is not greater than 15000…
The Pilots Brothers' refrigerator Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 22286   Accepted: 8603   Special Judge Description The game “The Pilots Brothers: following the stripy elephant” has a quest where a player needs to open a…
Flip Game Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 37427   Accepted: 16288 Description Flip game is played on a rectangular 4x4 field with two-sided pieces placed on each of its 16 squares. One side of each piece is white and the…
Corn Fields Time Limit: 2000MS   Memory Limit: 65536K Total Submissions: 9806   Accepted: 5185 Description Farmer John has purchased a lush new rectangular pasture composed of M by N (1 ≤ M ≤ 12; 1 ≤ N ≤ 12) square parcels. He wants to grow some yumm…
Sum of Consecutive Prime Numbers Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 20050   Accepted: 10989 Description Some positive integers can be represented by a sum of one or more consecutive prime numbers. How many such representatio…
Tree Recovery Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 11939   Accepted: 7493 Description Little Valentine liked playing with binary trees very much. Her favorite game was constructing randomly looking binary trees with capital le…
Seek the Name, Seek the Fame Time Limit: 2000MS   Memory Limit: 65536K Total Submissions: 17898   Accepted: 9197 Description The little cat is so famous, that many couples tramp over hill and dale to Byteland, and asked the little cat to give names t…
题目: poj 2352 Stars 数星星 题意:已知n个星星的坐标.每个星星都有一个等级,数值等于坐标系内纵坐标和横坐标皆不大于它的星星的个数.星星的坐标按照纵坐标从小到大的顺序给出,纵坐标相同时则按照横坐标从小到大输出. (0 <= x, y <= 32000) 要求输出等级0到n-1之间各等级的星星个数. 分析: 这道题不难想到n平方的算法,即从纵坐标最小的开始搜,每次找它前面横坐标的值比它小的点的个数,两个for循环搞定,但是会超时. 所以需要用一些数据结构去优化,主要是优化找 横坐…
poj   1251  Jungle Roads  (最小生成树) Link: http://poj.org/problem?id=1251 Jungle Roads Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 23507   Accepted: 11012 Description The Head Elder of the tropical island of Lagrishan has a problem. A b…
Kaka's Matrix Travels Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 9567   Accepted: 3888 Description On an N × N chessboard with a non-negative number in each grid, Kaka starts his matrix travels with SUM = 0. For each travel, Kaka mo…
Friendship Time Limit: 2000MS   Memory Limit: 20000K Total Submissions: 10626   Accepted: 2949 Description In modern society, each person has his own friends. Since all the people are very busy, they communicate with each other only by phone. You can…
Ikki's Story I - Road Reconstruction Time Limit: 2000MS   Memory Limit: 131072K Total Submissions: 7659   Accepted: 2215 Description Ikki is the king of a small country – Phoenix, Phoenix is so small that there is only one city that is responsible fo…
http://poj.org/problem?id=1144 题意:给你一些点,某些点直接有边,并且是无向边,求有多少个点是割点 割点:就是在图中,去掉一个点,无向图会构成多个子图,这就是割点 Tarjan算法求割点的办法 如果该点为根,那么它的子树必须要大于1 如果该点不为根,那么当low[v]>=dnf[u]时,为割点 Low[v]>=dnf[u]也就是说明U的子孙点只能通过U点访问U的祖先点 #include <stdio.h> #include <stack>…
http://poj.org/problem?id=3614 题意:有n头奶牛想要晒太阳,但他们每个人对太阳都有不同的耐受程度,也就是说,太阳不能太大也不能太小,现在有一种防晒霜,涂抹这个防晒霜可以把太阳的强度固定到一个值 求一共有多少头奶牛可以晒太阳 #include <stdio.h> #include <queue> #include <stdlib.h> using namespace std; int m,n; struct co{ int mi,ma; }c…