1 现值计算
2 训练计划
#include<iostream>
using namespace std;
int mymax(int a, int b)
{
if (a > b)return a;
return b;
}
int main()
{
int n, m;
int a[105];
int b[105];
int c[105];
int d[105] = { 0 };
cin >> n >> m;
int i, j;
for (i = 1; i <= m; i++)
{
cin >> a[i];
}
for (i = 1; i <= m; i++)
{
cin >> b[i];
}
int flag = 1;
for (i = 1; i <= m; i++)
{
if (a[i] == 0)
{
c[i] = 0;
if (flag)
{
cout << "1";
flag = 0;
}
else cout << " 1";
}
else
{
c[i] = c[a[i]] + b[a[i]];
cout << " " << c[i] + 1;
}
}
cout << endl;
int max = -1;
for (i = m; i > 0; i--)
{
d[i] += b[i];
if (d[i] > max)max = d[i];
if (a[i] != 0)
{
d[a[i]] = mymax(d[i],d[a[i]]);
}
}
if (max > n)return 0;
for (i = 1; i <= m; i++)
{
if (i == 1)
cout << n - d[i] + 1;
else cout << " " << n - d[i] + 1;
}
return 0;
}
3 JPEG 解码
#include<iostream>
#include<iomanip>
#include<algorithm>
#include<cstdio>
#include<cmath>
using namespace std;
int sequence[] = { 0,1,10,20,11,2,3,12,
21,30,40,31,22,13,4,5,
14,23,32,41,50,60,51,42,
33,24,15,6,7,16,25,34,
43,52,61,70,71,62,53,44,
35,26,17,27,36,45,54,63,
72,73,64,55,46,37,47,56,
65,74,75,66,57,67,76,77 };
float pi = 3.1415926535;
int q[10][10], m[10][10] = { 0 };
float m1[10][10];
float a(int u, int v)
{
if (u == 0 && v == 0)return 0.5;
else if (u == 0 && v != 0)return pow(0.5, 0.5);
else if (u != 0 && v == 0)return pow(0.5, 0.5);
else if (u != 0 && v != 0)return 1;
}
float f(int i, int j)
{
float sum = 0;
for (int ii = 0; ii < 8; ii++)
{
for (int jj = 0; jj < 8; jj++)
{
sum = sum + m[ii][jj] * a(ii, jj) * cos((i + 0.5) * pi * ii / 8) * cos((j + 0.5) * pi * jj / 8);
}
}
return sum / 4;
}
int main()
{
int i, j;
int n, T;
for (i = 0; i < 8; i++)
{
for (j = 0; j < 8; j++)
{
cin >> q[i][j];
}
}
cin >> n >> T;
for (i = 0; i < n; i++)
{
cin >> m[sequence[i] / 10][sequence[i] % 10];
}
if (T == 0)
{
for (i = 0; i < 8; i++)
{
for (j = 0; j < 8; j++)
{
if (j == 0)cout << m[i][j];
else cout << " " << m[i][j];
}
cout << endl;
}
}
else if (T == 1)
{
for (i = 0; i < 8; i++)
{
for (j = 0; j < 8; j++)
{
m[i][j] *= q[i][j];
if (j == 0)cout << m[i][j];
else cout << " " << m[i][j];
}
cout << endl;
}
}
else if (T == 2)
{
for (i = 0; i < 8; i++)
{
for (j = 0; j < 8; j++)
{
m[i][j] *= q[i][j];
}
}
int res;
for (i = 0; i < 8; i++)
{
for (j = 0; j < 8; j++)
{
m1[i][j] = f(i, j);
res = int(m1[i][j] + 128 + 0.5);
if (res > 255)res = 255;
if (res < 0)res = 0;
if (j == 0)cout << res;
else cout << " " << res;
}
cout << endl;
}
}
return 0;
}