HDU, hduacm
Problem DescriptionOnce upon a time Matt went to a small town. the town was so small and narrow that he can regard the town as a repository. there were some skyscrapers in the town, each located at position xi with its height hi. all skyscrapers located in different place. the skyscrapers had no width, to make it simple. as the skyscrapers were so high, Matt cocould hardly see the sky. given the position Matt was at, he wanted to know how large the angle range was where he cocould see the sky. assume that Matt's height is 0. it's guaranteed that for each query, there is at least one building on both Matt's left and right, and no building locate at his position.
InputThe first line of the input contains an integer T, denoting the number of testcases. Then T test cases follow.
Each test case begins with a number N (1 <= N <= 10 ^ 5), the number of buildings.
In the following N lines, each line contains two numbers, xi (1 <= xi <= 10 ^ 7) and hi (1 <= hi <= 10 ^ 7 ).
After that, there's a number Q (1 <= Q <= 10 ^ 5) for the number of queries.
In the following Q lines, each line contains one number qi, which is the position Matt was.
OutputFor each test case, first output one line "Case # x:", where x is the case number (starting from 1 ).
Then for each query, you shocould output the angle range Matt cocould see the sky in degrees. The relative error of the answer shocould be no more than 10 ^ (-4 ).
Sample Input
331 22 15 11431 32 25 11431 42 35 114
Sample Output
Case #:101. 3099324740 Case #2: 90.0000000000 Case #3: 78.6900675260 question: give you n buildings, each of which has a height and coordinates. Ask you to stand in a certain position, the thought of viewing the sky: Combine people and buildings for inquiry, sort the data, and maintain a monotonous stack with a convex height reduction (you can draw it by yourself ), then, every time a person's position is queried, the monotonous stack is maintained so that the image is convex. Then, the beginning of the stack and the person in the stack can constitute the answer, we also need to maintain this stack when building the building. We can use the tangent value to solve the problem after each traversal.#include <iostream>#include <cstdio>#include <cstring>#include <algorithm>#include <queue>#include <cmath>typedef __int64 ll;using namespace std;const double PI = acos(-1.0);const int maxn = 100005;struct Node {int x, h;bool operator <(const Node &a)const {return x < a.x;}} node[maxn<<2], stk[maxn<<2];double ans[maxn];int n, q;int check(Node &a, Node &b, Node c) {if (c.h <= 0)c.h = 0;return (ll)(a.h - c.h) * (c.x - b.x) >= (ll)(b.h - c.h) * (c.x - a.x);}double getAngle(Node a, Node b) {return atan((double)(b.x-a.x)/(double)(a.h));}void cal() {int head = 0;for (int i = 0; i < n+q; i++) {if (node[i].h <= 0) {while (head >= 2 && check(stk[head-2], stk[head-1], node[i]))head--;ans[-node[i].h] += getAngle(stk[head-1], node[i]);}else {while (head && stk[head-1].h <= node[i].h)head--;while (head >= 2 && check(stk[head-2], stk[head-1], node[i]))head--;stk[head++] = node[i];}}}int main() {int t, cas = 1;scanf("%d", &t);while (t--) {scanf("%d", &n);for (int i = 0; i < n; i++)scanf("%d%d", &node[i].x, &node[i].h);scanf("%d", &q);for (int i = 0; i < q; i++) {scanf("%d", &node[i+n].x);node[i+n].h = -i;}memset(ans, 0, sizeof(ans));sort(node, node+n+q);cal();reverse(node, node+n+q);for (int i = 0; i < n+q; i++)node[i].x = 10000000 - node[i].x;cal();printf("Case #%d:\n", cas++);for (int i = 0; i < q; i++)printf("%.10lf\n", ans[i] * 180.0 / PI);}return 0;}
Hdu acm 2032.
I will send you my ac code to check whether there are any extra spaces in the output. Let's take a look. Come on.
# Include <stdio. h>
Int main ()
{
Int n;
While (scanf ("% d", & n )! = EOF)
{
Int a [31] [31];
Int I, j, k;
For (I = 1; I <= 30; I ++)
A [I] [1] = a [I] [I] = 1;
If (n = 1) printf ("1 \ n ");
If (n> = 2) printf ("1 \ n1 1 \ n ");
For (I = 3; I <= n; I ++)
{
Printf ("1 ");
For (j = 2; j <I; j ++)
{
A [I] [j] = a [I-1] [j] + a [I-1] [J-1];
Printf ("% d", a [I] [j]);
}
Printf ("% d \ n", a [I] [I]);
}
Printf ("\ n ");
}
}
Hdu 1004 Runtime Error (ACCESS_VIOLATION)
There are a lot of problems... the following code can ac
STACK_OVERFLOW refers to stack space overflow. google is recommended for Stack. It is shown that a is too large to open a large array.
ACCESS_VIOLATION is generally because the array is out of bounds. Here, you are shown as B is too small. When n> 100, the subscript I and j will be out of bounds.
# Include <stdio. h>
# Include <string. h>
Char a [1001] [20]; // 500 is changed to WA, and STACK_OVERFLOW is changed to WA.
Int main ()
{
Int B [1001], I, maxi, max, j, n;
While (scanf ("% d", & n )! = EOF)
{
If (n = 0) break; // The end condition given by the question stem. Do not ignore this condition.
For (I = 0; I <n; I ++)
Scanf ("% s", a [I]);
For (I = 0; I <n; I ++)
{
B [I] = 0;
For (j = I + 1; j <n; j ++)
If (strcmp (a [j], a [I]) = 0)
B [I] ++;
}
Max = B [0];
For (I = 0; I <n; I ++)
If (B [I]> = max)
{Max = B [I];
Maxi = I;
}
Printf ("% s \ n", a [maxi]);
}
Return 0;
}