实训week4:模拟专题

最简单的一章,没有之一

练习题目:

EOJ 3004

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
#include <iostream>
using namespace std;
int main(){
int T;
cin >> T;
for(int step = 0;step < T;step++){
int p, e, i, d;
cin >> p >> e >> i >> d;
p %= 23,e %= 28,i %= 33;
int res;
for(int res = d+1;res <= 21252+d;res++)
if(res%23 == p && res%28 == e && res%33 == i){
cout << "case #" << step << ":\n";
cout << "the next triple peak occurs in " << res-d << " days." << endl;
break;
}
}
return 0;
}

EOJ 2993

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
#include <iostream>
#include <vector>
using namespace std;
int main(){
int T;
cin >> T;
for(int step = 0;step < T;step++){
vector<int> vec;
int N;
cin >> N;
for(int i = 0;i < N;i++){
int temp;
cin >> temp;
vec.push_back(temp);
}
int cnt;
do{
cnt = 0;
for(int i = 0;i < vec.size();i++){
int sum = 0;
for(int j = i;j < vec.size();j++){
if(vec[i] > vec[j])
sum++;
}
if(vec[i] != sum)
cnt++;
vec[i] = sum;
}
}while(cnt != 0);
cout << "case #" << step << ":\n";
cout << vec[0];
for(int i = 1;i < vec.size();i++)
cout << " " << vec[i];
cout << endl;
}
return 0;
}

EOJ 2968

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
#include <iostream>
using namespace std;
int main(){
int T;
cin >> T;
for(int step = 0;step < T;step++){
int n;
cin >> n;
int arr[6] = {0,0,0,0,0,0};
while(n){
if(n >= 100)n -= 100, arr[0]++;
else if(n >= 50)n -= 50, arr[1]++;
else if(n >= 20)n -= 20, arr[2]++;
else if(n >= 10)n -= 10, arr[3]++;
else if(n >= 5)n -= 5, arr[4]++;
else if(n >= 1)n -= 1, arr[5]++;
}
cout << "case #" << step << ":\n";
cout << arr[0] << " " << arr[1] << " " << arr[2] << " " << arr[3] << " " << arr[4] << " " << arr[5] << endl;
}
return 0;
}

EOJ 2970

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
#include <iostream>
using namespace std;
int main(){
int T;
cin >>T;
for(int step = 0;step < T;step++){
int N, M;
cin >> N >> M;
int a, b;
cout << "case #" << step << ":\n";
a = (4*N-M)/2;
b = (M-2*N)/2;
if(((a = (4*N-M)/2) == (4*N-M)/2.0) && ((b = (M-2*N)/2) == (M-2*N)/2.0) && a >= 0 && b >= 0)
cout << a << " " << b << endl;
else
cout << "Impossible" << endl;
}
return 0;
}

EOJ 2984

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
#include <iostream>
using namespace std;
int main(){
int T;
cin >> T;
for(int step = 0;step < T;step++){
int N, K;
cin >> N >> K;
int m,w;
cout << "case #" << step << ":\n";
if(K > 3*N || N > K)
cout << "-1" << endl;
else
for(m = 0;m <= N;m++)
for(w = 0;w <= N;w++)
if(N-m-w == K-3*m-2*w)
cout << m << " " << w << " " << (K-3*m-2*w) << endl;
}
return 0;
}

EOJ 3003

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
#include <iostream>
#include <algorithm>
using namespace std;
int main(){
int T;
cin >> T;
for(int step = 0;step < T;step++){
int n;
cin >> n;
int arr1[n], arr2[n];
for(int i = 0;i < n;i++)
cin >> arr1[i];
for(int i = 0;i < n;i++)
cin >> arr2[i];
sort(arr1, arr1+n, less<int>());
sort(arr2, arr2+n, greater<int>());
int res = 0;
for(int i = 0;i < n;i++)
res += arr1[i]*arr2[i];
cout << "case #" << step << ":\n";
cout << res << endl;
}
return 0;
}