Fork me on GitHub

数学专题习题

题目传送门

UVa-10237
UVa-10883
UVa-10943
UVa-11038
UVa-11076
UVa-11388
UVa-11889

Code

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
//UVA-10237
#include<bits/stdc++.h>
using namespace std;

typedef long long ll;
const int N = 40;

int n, k;
ll b[N][N*N],w[N][N*N];

void init()
{
memset(b, 0, sizeof(b));
memset(w, 0, sizeof(w));
b[0][0] = w[1][0] = 1;
for (int i = 1; i <= n; i++)
{
b[i][0] = b[i-1][0];

int l = (i+1)/2 * 2 - 1;
for (int j = 1; j <= l && j <= k; j++)
b[i][j] = b[i-1][j] + (ll)(l-j+1) * b[i-1][j-1];
}

for (int i = 2; i <= n; i++)
{
w[i][0] = w[i-1][0];

int l = i/2 * 2;
for (int j = 1; j <= l && j <= k; j++)
w[i][j] = w[i-1][j] + (ll)(l-j+1) * w[i-1][j-1];
}
}

int main (int argc, char *argv[])
{
while (scanf("%d%d", &n, &k) == 2 && n + k)
{
init();
ll ans = 0;
for (int i = 0; i <= k; i++)
ans = ans + b[n][i] * w[n][k-i];
printf("%lld\n", ans);
}
return 0;
}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
//UVA-10883
#include<bits/stdc++.h>
using namespace std;
int T,n,kase = 0;
double ln[50010],a;
void init(void)
{
ln[0] = ln[1] = 0;
for (int i = 2; i <= 50009; i++)
ln[i] = ln[i-1]+log(i);
}
int main(int argc, char *argv[])
{
init();
cin >> T;
while(T--)
{
cin >> n;
n--;
double summ = 0.0;
for (int i = 0; i <= n; i++)
{
cin >> a;
summ += a * exp(ln[n]-ln[n-i]-ln[i]-n*ln[2]);
}
printf("Case #%d: %.3lf\n",++kase,summ);
}
return 0;
}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
//UVA-10943
#include<bits/stdc++.h>
using namespace std;
int N,K;
int C[210][210];
const int module = 1e6;
void in_table(void)
{
for (int i = 0; i <= 208; i++)
for (int j = 0; j <= i; j++)
{
if (i == j) C[i][j] = 1;
else C[i][j] = (C[i-1][j-1]+C[i-1][j])%module;
}
}
int main(int argc, char *argv[])
{
in_table();
while(scanf("%d %d",&N,&K) == 2 && N && K)
{printf("%d\n",C[N+K-1][K-1]);}
return 0;
}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
//UVA-11038
#include<bits/stdc++.h>
using namespace std;
#define int long long
int m,n;
int f[13],g[13]; //10^i~10^(i+1)-1
int calc(int x)
{
int ans=1,cnt=1,tmp=0;
if (x < 0)
return 0;
while(x)
{
int c = x%10;
x/=10;
if (c) ans+=x*cnt;
else ans+=(x-1)*cnt+tmp+1;
tmp+=c*cnt;
cnt*=10;
}
return ans;
}
signed main(signed argc, char *argv[])
{
f[0] = g[0] = 1;
for (int i = 1; i <= 11; i++)
f[i] = (9*(i-1))*i+i;
for (int i = 1; i <= 11; i++) g[i] = g[i-1]+f[i];
while(scanf("%lld%lld",&n,&m) == 2 && n >= 0 && m >= 0)
printf("%lld\n",calc(m)-calc(n-1));
return 0;
}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
//UVA-11076
#include<bits/stdc++.h>
using namespace std;
int n,a[13],c[11],d[11];
unsigned long long ans,t = 1;
unsigned long long op(int x)
{
unsigned long long ret = 1;
int y=x;
while(y) ret*=y,y--;
return ret;
}
unsigned long long op1(int x)
{
unsigned long long ret = 0;
while(x)
{
x--;
ret+=pow(10,x);
}
return ret;
}
int main(int argc, char *argv[])
{
while(scanf("%d",&n) == 1 && n)
{
memset(c,0,sizeof(c));
for (int i = 1; i <= n; i++) scanf("%d",&a[i]),c[a[i]]++;
unsigned long long f = op(n),mul = op1(n);
for (int i = 0; i <= 9; i++) f/=(op(c[i]));
for (int i = 0; i <= 9; i++) d[i] = f*c[i]/n;
ans = 0;
for (int i = 0; i <= 9; i++) ans += d[i]*i*mul;
cout << ans << endl;
}
return 0;
}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
//UVA-11388
#include<bits/stdc++.h>
using namespace std;
int T;
#define LL long long
long long gcd(long long x,long long y)
{
return (y == 0) ? x : gcd(y,x%y);
}
int main(int argc, char *argv[])
{
ios::sync_with_stdio(false);
long long T,G,L;
cin >> T;
while(T--)
{
int flag = 0;
cin >> G >> L;
if (L % G != 0)
{
cout << "-1" << endl;
continue;
}
else
{
cout << G << " " << L << "\n";
continue;
}
/*
long long x = G*L;
for (long long i = G; i <= min((LL)sqrt(x),L); i++)
{
if (x % i == 0)
{
if (gcd(i,x/i) == G)
{
printf("%lld %lld\n",i,x/i);
flag = 1;
break;
}
}
}
if (!flag) printf("-1\n");*/
}

return 0;
}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
//UVA-11889
#include<bits/stdc++.h>
using namespace std;
#define int long long
long long gcd(long long x,long long y)
{
return (y == 0) ? x : gcd(y,x%y);
}
signed main(signed argc, char *argv[])
{
int A,C,T;
ios::sync_with_stdio(false);
cin >> T;
while(T--)
{
int flag = 1;
cin >> A >> C;
for (int i = 1; i <= A; i++)
if (i*C % A == 0)
{
int B = i * C/A;
if (gcd(A,B) == i)
{
printf("%d\n",B);
flag = 0;
break;
}
}
if (flag) puts("NO SOLUTION");
}
return 0;
}