EOJ:2018 年计算机系夏令营机考

2021/6/29 23:20:47

本文主要是介绍EOJ:2018 年计算机系夏令营机考,对大家解决编程问题具有一定的参考价值,需要的程序猿们随着小编来一起学习吧!

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;
			}
		}
		
	}
	
	
}


这篇关于EOJ:2018 年计算机系夏令营机考的文章就介绍到这儿,希望我们推荐的文章对大家有所帮助,也希望大家多多支持为之网!


扫一扫关注最新编程教程