poj 2481】的更多相关文章

题目传送门 #include <cstdio> #include <cstring> #include <algorithm> using namespace std; + ; int cnt[MAX_N]; int ans[MAX_N]; ; struct node { int s, e; int id; }cow[MAX_N]; inline int read(void) { , f = ; char ch = getchar (); ; ch = getchar…
题目链接:http://poj.org/problem?id=2481 给你n个区间,让你求每个区间被真包含的区间个数有多少,注意是真包含,所以要是两个区间的x y都相同就算0.(类似poj3067,cf652D) 对每个区间的x从小到大排序,相同的话按y从大到小排序.然后对枚举每个区间的y求其逆序对,然后在y的位置上置1.但是存在两个区间完全重合,我的做法比较搓,就是判断和前一个区间是否完全相同,要是相同,就把前一个答案赋值给这个. #include <iostream> #include…
[题目链接] http://poj.org/problem?id=2481 [算法] 树状数组 注意特判两头牛的s,e值相同 [代码] #include <algorithm> #include <bitset> #include <cctype> #include <cerrno> #include <clocale> #include <cmath> #include <complex> #include <cs…
Cows 题目:http://poj.org/problem?id=2481 题意:有N头牛,每仅仅牛有一个值[S,E],假设对于牛i和牛j来说,它们的值满足以下的条件则证明牛i比牛j强壮:Si <=Sjand Ej <= Ei and Ei - Si > Ej - Sj. 如今已知每一头牛的測验值,要求输出每头牛有几头牛比其强壮. 思路:将牛依照S从小到大排序.S同样依照E从大到小排序,这就保证了排在后面的牛一定不比前面的牛强壮. 再依照E值(离散化后)建立一颗线段树(这里最值仅仅有1…
Cows Time Limit: 3000MS   Memory Limit: 65536K Total Submissions: 16163   Accepted: 5380 Description Farmer John's cows have discovered that the clover growing along the ridge of the hill (which we can think of as a one-dimensional number line) in hi…
Cows Time Limit: 3000MS   Memory Limit: 65536K Total Submissions: 16546   Accepted: 5531 Description Farmer John's cows have discovered that the clover growing along the ridge of the hill (which we can think of as a one-dimensional number line) in hi…
Cows Time Limit: 3000MS Memory Limit: 65536K Description Farmer John's cows have discovered that the clover growing along the ridge of the hill (which we can think of as a one-dimensional number line) in his field is particularly good. Farmer John ha…
Cows Time Limit: 3000MS   Memory Limit: 65536K Total Submissions: 14906   Accepted: 4941 Description Farmer John's cows have discovered that the clover growing along the ridge of the hill (which we can think of as a one-dimensional number line) in hi…
看的人家的思路,没有理解清楚,,, 结果一直改一直交,,wa了4次才交上,,, 注意: 为了使用树状数组,我们要按照e从大到小排序.但s要从小到大.(我开始的时候错在这里了) 代码如下: #include <cstdio> #include <cstdlib> #include <cmath> #include <cstring> #include <cstdlib> #include <stack> #include <que…
                                                                  Cows Time Limit: 3000MS   Memory Limit: 65536K Total Submissions: 17626   Accepted: 5940 Description Farmer John's cows have discovered that the clover growing along the ridge of the h…
题意:对于两个区间,[si,ei] 和 [sj,ej],若 si <= sj and ei >= ej and ei - si > ej - sj 则说明区间 [si,ei] 比 [sj,ej] 强.对于每个区间,求出比它强的区间的个数. 解题思路:先将每个区间按 e 降序排列,在按 s 升序排列.则对于每个区间而言,比它强的区间的区间一定位于它的前面. 利用数状数组求每个区间[si,ei]前面 满足条件的区间[sj,ej]个数(条件:ej<=ei),再减去前面的和它相同的区间的个…
Cows Time Limit: 3000MS   Memory Limit: 65536K Total Submissions: 15301   Accepted: 5095 Description Farmer John's cows have discovered that the clover growing along the ridge of the hill (which we can think of as a one-dimensional number line) in hi…
<题目链接> 题目大意: 就是给出N个区间,问这个区间是多少个区间的真子集. 解题分析: 本题与stars类似,只要巧妙的将线段的起点和终点分别看成 二维坐标系中的x,y坐标,就会发现,其实本题就是求每个点(把线段看成点) 左上角点的个数(包括边界,但并不包括与该点坐标完全相同的点),所以,与stars类似,对所有线段先进行排序,按 y坐标由大到小排序,若左边相同,就对x坐标进行从小到大排序.然后就可以直接对每个点的x坐标建立一维树状数组求解了. #include <cstdio>…
Description Farmer John's cows have discovered that the clover growing along the ridge of the hill (which we can think of as a one-dimensional number line) in his field is particularly good. Farmer John has N cows (we number the cows from 1 to N). Ea…
Farmer John's cows have discovered that the clover growing along the ridge of the hill (which we can think of as a one-dimensional number line) in his field is particularly good. Farmer John has N cows (we number the cows from 1 to N). Each of Farmer…
题意:给出n头牛的s,e 如果有两头牛,现在si <= sj && ei >= ej 那么称牛i比牛j强壮 然后问每头牛都有几头牛比它强壮 先按照s从小到大排序,然后用e来当做树状数组里面那个a数组,对于每头牛求出前面比他大的e有多少个 还有就是注意有两头牛的s和e相等的情况,就只需要更新值, #include<iostream> #include<cstdio> #include<cstring> #include <cmath>…
Cows 思路:我们可以按照每个范围的S从小到大排序,相同的S按E从大到小排序,这样的好处是当前范围的S一定大于等于之前范围的S(即当前的范围可能被之前范围的包围),那么我们只需要统计之前的范围E比当前的范围E大于等于的有几个即可.这里需要注意如果两个范围完全相同的情况,我们可以把当前的范围与之前的范围比较,如果相同,直接把之前的答案复制到当前就可. #include <iostream> #include <cstdio> #include <queue> #incl…
总结一下树状数组的题目: {POJ}{3928}{Ping Pong} 非常好的题目,要求寻找一个数组中满足A[i]<A[k]<A[j]的个数,其中i<k<j(或者相反).很巧妙的将题目转化为树状数组的思想,从A[k]考虑,则只需要寻找左边比自己小和右边比自己大的可能性(或者相反),这样就可以用树状数组来维护.思想的转变很重要. {POJ}{1990}{MooFest} n头牛,不同的听力值v,当i,j想要通话时,需要max(v(i),v(j))*(dist[i]-dist[j])…
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…