T1:
#include <iostream>
#include <algorithm>
#include <unordered_map>
using namespace std;
const int N = 100010;
struct teacher
{
int years;
bool operator < (const teacher & t) const {
return years < t.years;
}
}tea[N];
int main()
{
int n;
cin >> n;
unordered_map<int, int> cnt;
unordered_map<int, bool> printed;
for (int i = 0; i < n ; i ++ ) {
cin >> tea[i].years;
cnt[tea[i].years] ++;
}
stable_sort(tea, tea + n);
for (int i = 0; i < n ; i ++ ) {
if (!printed[tea[i].years]) {
cout << tea[i].years << " : " << cnt[tea[i].years] << endl;
printed[tea[i].years] = true;
}
}
}
T2:
#include <iostream>
using namespace std;
const int N = 1010, M = 1010;
int f[N][M];
int n, m, q;
int cnt(int x1, int y1, int x2, int y2)
{
int res = 0;
for (int i = x1; i <= x2; i ++ )
for (int j = y1; j <= y2; j ++ ) {
res += f[i][j];
}
return res;
}
int main()
{
cin >> n >> m >> q;
for (int i = 1; i <= n ; i ++ )
for (int j = 1; j <= m ; j ++)
cin >> f[i][j];
while (q -- ) {
int x1, y1, x2, y2;
cin >> x1 >> y1 >> x2 >> y2;
cout << cnt(x1, y1, x2, y2) << endl;
}
return 0;
}
T3:
#include <iostream>
using namespace std;
const int N = 35;
int f[N];
int main()
{
int n;
cin >> n;
f[1] = 1, f[2] = 2;
/*对于n>2的情况,考虑最后一步的走法。
如果最后一步是走了一级台阶到达第n级,那么前面n - 1级台阶的走法方案数为f(n - 1)种;
如果最后一步是走了两级台阶到达第n级,那么前面n-2级台阶的走法方案数为f(n - 2)种。
所以走到第n级台阶的总方案数f(n)=f(n - 1)+f(n - 2),这正好符合斐波那契数列的递推公式。*/
for (int i = 3; i <= n; i ++ )
f[i] = f[i-1] + f[i-2];
cout << f[n] << endl;
return 0;
}