EOJ地址:https://acm.ecnu.edu.cn/contest/97/
纯个人解法,如有更简单的方法,欢迎交流。
Problem A. 图像卷积(easy)
#include<bits/stdc++.h>
using namespace std;
int n,m,h,w;
int main(){
cin>>n>>m;
vector<int> myvect[n];
for(int i =0;i<n;i++){
for(int j =0;j<m;j++){
int temp;
cin>>temp;
myvect[i].push_back(temp);
}
}
cin>>h>>w;
vector<int> kel[n];
for(int i =0;i<h;i++){
for(int j =0;j<w;j++){
int temp;
cin>>temp;
kel[i].push_back(temp);
}
}
for(int i =0;i<n-h+1;i++){
for(int j = 0;j<m-w+1;j++){
int sum = 0;
for(int x = 0;x<h;x++){
for(int y = 0;y<w;y++){
sum+=myvect[i+x][y+j]*kel[x][y];
}
}
cout<<sum;
if(j==m-w) cout<<endl;
else cout<<" ";
}
}
}
Problem B. 白网吧(这题我抄的)
#include<bits/stdc++.h>
#define LL long long
using namespace std;
int n, m, q;
LL totalTime;
LL gcd(LL a, LL b) {
return !b ? a : gcd(b, a % b);
}
int main() {
cin >> n >> m;
vector<pair<int, int> > arr(2 * n);
int num = 0;
for (int i = 0; i < n; i++) {
int l, r;
cin >> l >> r;
totalTime += r - l + 1;
arr[num++] = make_pair(l, 0);
arr[num++] = make_pair(r, 1);
}
cin >> q;
sort(arr.begin(),arr.end());
int cnt = 0, maxPerson = 1;
for (int i = 0; i < 2 * n; i++) {
if (arr[i].second == 0) {
cnt++;
maxPerson = max(maxPerson, cnt);
}
else {
cnt--;
}
}
LL k = gcd(totalTime, m);
if (q == 1) {
cout << maxPerson;
}
else if (q == 2) {
cout << totalTime / k << "/" << m / k;
}
else if (q == 3) {
cout << maxPerson << "\n";
cout << totalTime / k << "/" << m / k;
}
}
Problem C. 皇后问题(爷尽力了)
#include<bits/stdc++.h>
using namespace std;
int n,m,x,y;
int main(){
cin>>n>>m>>x>>y;
if(x==1 && y==1){
for(int i =1;i<=n;i++){
for(int j=1;j<=m;j++){
if(i==1 && j==1) continue;
if(i%2==1) cout<<i<<" "<<j<<endl;
else cout<<i<<" "<<m-j+1<<endl;
}
}
}
else if(x!=1&&y!=1){
int temp=y;
int flag=0;
while(temp!=m) cout<<x<<" "<<++temp<<endl;
temp=y;
while(temp!=1) cout<<x<<" "<<--temp<<endl;
for(int i =1;i<=n;i++){
if(i==x) continue;
flag=!flag;
for(int j =1;j<=m;j++){
if(flag%2==0) cout<<i<<" "<<m-j+1<<endl;
else cout<<i<<" "<<j<<endl;
}
}
}
else if(x==1&&y!=1){
int temp=y;
while(temp!=m) cout<<1<<" "<<++temp<<endl;
temp=y;
while(temp!=1) cout<<1<<" "<<--temp<<endl;
for(int i =2;i<=n;i++){
for(int j=1;j<=m;j++){
if(i%2==0) cout<<i<<" "<<j<<endl;
else cout<<i<<" "<<m-j+1<<endl;
}
}
}
else{
int temp=y;
int flag=0;
while(temp!=m) cout<<x<<" "<<++temp<<endl;
for(int i =1;i<=n;i++){
if(i==x) continue;
flag=!flag;
for(int j =1;j<=m;j++){
if(flag%2==1) cout<<i<<" "<<m-j+1<<endl;
else cout<<i<<" "<<j<<endl;
}
}
}
}