HDU, hdu.edu.cn
Problem DescriptionNumber theory is interesting, while this problem is boring.
Here is the problem. Given an integer sequence a1, a2 ,..., An, let S (I) = {j | 1 <= j <I, and aj is a multiple of ai }. if S (I) is not empty, let f (I) be the maximum integer in S (I); otherwise, f (I) = I. now we define B I as af (I ). similarly, let T (I) = {j | I <j <= n, and aj is a multiple of ai }. if T (I) is not empty, let g (I) be the minimum integer in T (I); otherwise, g (I) = I. now we define ci as ag (I ). the boring sum of this sequence is defined as b1 * c1 + b2 * C2 +... + Bn * cn.
Given an integer sequence, your task is to calculate its boring sum.
InputThe input contains multiple test cases.
Each case consists of two lines. The first line contains an integer n (1 <=n <= 100000). The second line contains n integers a1, a2 ,..., An (1 <= ai <= 100000 ).
The input is terminated by n = 0.
OutputOutput the answer in a line.
Sample Input
51 4 2 3 90
Sample Output
136 question: Give you an array and let you generate two new arrays. A requires that each number be located before it. If you can find the nearest one, which is A multiple of it, then it will be the number. Otherwise it will be your own, C will be looking for it later, and the idea of output crossover and multiplication will be: scanning record factor Processing#include <iostream>#include <cstdio>#include <cstring>#include <algorithm>#include <cmath>using namespace std;typedef __int64 ll; const int MAXN = 100005;int a[MAXN], b[MAXN], c[MAXN], vis[MAXN];int n;int main() {while (scanf("%d", &n) == 1) {if (n == 0)break;for (int i = 1; i <= n; i++) scanf("%d", &a[i]); memset(vis, 0, sizeof(vis));for (int i = 1; i <= n; i++) {if (vis[a[i]])b[i] = a[vis[a[i]]];elseb[i] = a[i];for (int j = 1; j <= (int)sqrt((double)a[i]+0.5); j++) {if (a[i] % j == 0) {vis[j] = i;vis[a[i] / j] = i;}}}memset(vis, 0, sizeof(vis));for (int i = n; i >= 1; i--) {if (vis[a[i]])c[i] = a[vis[a[i]]];elsec[i] = a[i];for (int j = 1; j <= (int)sqrt((double)a[i]+0.5); j++) {if (a[i] % j == 0) {vis[j] = i;vis[a[i] / j] = i;}}}ll sum = 0;for (int i = 1; i <= n; i++) {sum += (ll)b[i] * c[i]; }printf("%I64d\n", sum); }return 0;}
Hdu acm 2036 I think I'm right
You have a problem with the method. I did not take it into consideration. Is it Helen's formula? This method loses precision...
Calculate the area of a triangle using the cross multiplication of the vector, thus losing precision .. If you don't know, go to the HDOJ forum and check the LCY courseware ..
Courseware: (apply for a number.) acm.hdu.edu.cn/forum/read.php? Tid = 3608
My AC code:
# Include <math. h>
Void main ()
{
Int n, x [150], y [150], x1, y1, x2, y2, I;
Double s;
While (scanf ("% d", & n )! = EOF, n)
{
S = 0;
For (I = 1; I <= n; I ++)
Scanf ("% d", & x [I], & y [I]);
For (I = 2; I <n; I ++)
{
X1 = x [1]-x [I];
Y1 = y [1]-y [I];
X2 = x [1]-x [I + 1];
Y2 = y [1]-y [I + 1];
S = s + (x1 * y2-y1 * x2)/2.0; // calculate the area of the Cross multiplication ..
}
Printf ("%. 1lf \ n", s );
}
}
HDU 1002
I don't know. I don't know what you wrote. You can check out my code. AC
Code:
# Include <stdio. h>
# Include <string. h>
Int main ()
{
Char a [1, 5001], B [2, 5001];
Int aa [5001], bb [5001], k, n = 0;
Scanf ("% d", & k );
For (int c = 1; c <= k; c ++)
{
Scanf ("% s", a, B );
Int alen = strlen ();
Int blen = strlen (B );
Memset (aa, 0, sizeof (aa); // clear the value in aa and set it to 0.
Memset (bb, 0, sizeof (bb ));
Int maxlen = blen;
If (alen> blen) maxlen = alen;
For (int I = alen-1; I> = 0; I --)
Aa [alen-I] = a [I]-'0 ';
For (int I = blen-1; I> = 0; I --)
Bb [blen-I] = B [I]-'0 ';
For (int I = 1; I <= maxlen; I ++)
{
Aa [I] + = bb [I];
If (aa [I]> 9)
{
If (I = maxlen) maxlen ++;
Aa [I + 1] ++;
Aa [I]-= 10;
}
}
Printf ("Case % d: \ n", ++ n );
Printf ("% s + % s =", a, B );
For (int I = maxlen; I> = 1; I --)
Printf ("% d", aa [I]);
If (k = c)
Printf ("\ n ");
Else
Printf ("\ n ");
}
Return 0;
}