【HDOJ DIYContest 37015&37016】ZUST2020新生训练

Contests

在这里插入图片描述
在这里插入图片描述

37015

1001

#include<bits/stdc++.h>
using namespace std;
int main(){
	cout<<"Hello World\n";
	return 0;
}

1002

#include<bits/stdc++.h>
using namespace std;
int main(){
	int a, b;
	cin>>a>>b;
	cout<<a+b<<endl;
	return 0;
}

1003

#include<bits/stdc++.h>
using namespace std;
int main(){
	int a, b;
	while(cin>>a>>b){
		cout<<a+b<<"\n";
	}
	return 0;
}

1004

#include<bits/stdc++.h>
using namespace std;
int main(){
	int T;  cin>>T;
	while(T--){
		int a, b;
		cin>>a>>b;
		cout<<a+b<<endl;
	}
	return 0;
}

1005

#include<bits/stdc++.h>
using namespace std;
int main(){
	int a, b;
	while(cin>>a>>b &&a &&b){
		cout<<a+b<<endl;
	}
	return 0;
}

1006

#include<bits/stdc++.h>
using namespace std;
int main(){
	double a, b;
	while(cin>>a>>b){
		cout<<fixed<<setprecision(6)<<a*b<<endl;
	}
	return 0;
}

1007

#include<bits/stdc++.h>
using namespace std;
int main(){
	double a, b;
	while(cin>>a>>b){
		cout<<"the answer is ";
		if(a>0&&b>0)cout<<1;
		if(a>0&&b<0)cout<<4;
		if(a<0&&b>0)cout<<2;
		if(a<0&&b<0)cout<<3;
		cout<<".\n";
	}
	return 0;
}

1008

#include<bits/stdc++.h>
using namespace std;
int main(){
	long long a,b,c;
	while(cin>>a>>b>>c){
		cout<<a+b-c<<endl;
	}
	return 0;
}

1009

#include<bits/stdc++.h>
using namespace std;
int main(){
	int cnt = 1;
	long long a,b,c;
	while(cin>>a>>b){
		cout<<"Case #"<<cnt++<<": ";
		cout<<a+b<<endl;
	}
	return 0;
}

1010

#include<bits/stdc++.h>
using namespace std;
int main(){
	char a;
	while(cin>>a){
		a -= 'a'-'A';
		cout<<a<<endl;
	}
	return 0;
}

1011

#include<bits/stdc++.h>
using namespace std;
#define mod 10007
int f[10010];
int main(){
	f[1] = 1;
	for(int i = 2; i <= 10000; i++)
		f[i] = f[i-1]*i%mod;
	int n;
	while(cin>>n){
		cout<<f[n]<<endl;		
	}
	return 0;
}

1012

#include<bits/stdc++.h>
using namespace std;
const int maxn = 110;
int n, a[maxn];
int main(){
	while(cin>>n){
		int sum = 0;
		for(int i = 1; i <= n; i++)cin>>a[i],sum+=a[i];
		cout<<sum<<endl;
		for(int i = 1; i <= n; i++){
			if(i!=1)cout<<" ";
				cout<<a[i];
		}
			
		cout<<endl;
	}
	return 0;
}

1013

#include<bits/stdc++.h>
using namespace std;
const int maxn = 110;
int main(){
	int ea, eb;
	cin>>ea>>eb;
	int a, b;
	while(cin>>a>>b){
		if(a==ea&&b==eb)break;
		cout<<a+b<<endl;
	}
	return 0;
}

1014

#include<bits/stdc++.h>
using namespace std;
const int maxn = 110;
int f[maxn];
int main(){
	int n;
	int ea, eb;
	//cin>>ea>>eb;
	int a, b;
	while(cin>>n){
		for(int i = 1; i <= n; i++)cin>>f[i];
		for(int i = n; i >= 1; i--){
			if(i!=n)cout<<" ";
			cout<<f[i];
		}
		cout<<endl;
	}
	return 0;
}

1015

#include<bits/stdc++.h>
using namespace std;
const int maxn = 110;
int f[maxn];
int main(){
	int n;
	int ea, eb;
	//cin>>ea>>eb;
	int a, b;
	string s, t;
	while(cin>>s){
		cout<<s.size()<<endl;
		cout<<s<<endl;
	}
	return 0;
}

1016

#include<bits/stdc++.h>
using namespace std;
const int maxn = 110;
int a[maxn][maxn];
int main(){
	int n, m, sum = 0;
	while(cin>>n>>m){
		sum = 0;
		for(int i = 1; i <= n; i++){
			for(int j = 1; j <= m; j++){
				cin>>a[i][j];
				sum += a[i][j];
			}
		}
		cout<<sum<<endl;
		for(int i = 1; i <= n; i++){
			for(int j = 1; j <= m; j++){
				if(j!=1)cout<<" ";
				cout<<a[i][j];
			}
			cout<<endl;
		}
	}
	return 0;
}

1017

#include<bits/stdc++.h>
using namespace std;
const int maxn = 110;
int a[maxn][maxn];
int main(){
	int n, m, sum = 0;
	while(cin>>n>>m){
		memset(a,0,sizeof(a));
		int cnt = 1, i = 1, j = 1; a[i][j]=1;
		while(cnt<n*m){
			while(j+1<=m && !a[i][j+1])a[i][++j]=++cnt;
			while(i+1<=n && !a[i+1][j])a[++i][j]=++cnt;
			while(j-1>=1 && !a[i][j-1])a[i][--j]=++cnt;
			while(i-1>=1 && !a[i-1][j])a[--i][j]=++cnt;
		}
		for(int i = 1; i <= n; i++){
			for(int j = 1 ; j<= m; j++){
				if(j!=1)cout<<" ";
				cout<<a[i][j];
			}
			cout<<endl;
		}
	}
	return 0;
}

1018

#include<bits/stdc++.h>
using namespace std;
const int maxn = 110;
//int a[maxn][maxn];
int f(int x){
	return  3 * x - 6 * x * (x + 3) + 29 * (x + 2) * (x - 1);
} 
int main(){
	int a, b, c, d;
	while(cin>>a>>b>>c>>d){
		cout<<f(a)+f(b)+f(c)+f(d)<<endl;
	}
	return 0;
}

1019

#include<bits/stdc++.h>
using namespace std;
const int maxn = 110;
//int a[maxn][maxn];
int F(int x){
	return x*3+((x-1)*6+4)+3;
} 

int G(int x){
	return F(x)*2-F(x)*F(x-1);
}
int K(int x){
	return G(x)*(G(2)-F(4));
}
int main(){
	int a, b, c, d;
	while(cin>>a>>b){
		cout<<K(a)-K(b)<<endl;
	}
	return 0;
}

1020

#include<bits/stdc++.h>
using namespace std;
const int maxn = 110;
//int a[maxn][maxn];
int F(int x){
	if(x==1||x==2)return 1;
	return F(x-1)+F(x-2);
} 
int main(){
	int a, b, c, d;
	while(cin>>a){
		cout<<F(a)<<endl;
	}
	return 0;
}

1021

#include<bits/stdc++.h>
using namespace std;
typedef long long LL;
const int maxn = 1100;
LL f[maxn];
/*
int F(int x){
	if(f[x])return f[x];
	if(x==1||x==2)return f[x] = 1;
	return f[x] = F(x-1)+F(x-2);
} 
*/
int main(){
	LL a, b, c, d;
	f[1] = f[2] = 1;
	for(int i = 3; i <= 100; i++)
		f[i] = f[i-1]+f[i-2];
	while(cin>>a){
		cout<<f[a]<<endl;
	}
	return 0;
}

1022

#include<bits/stdc++.h>
using namespace std;
const int maxn = 1100;
int f[maxn][maxn];
/*
int F(int x){
	if(f[x])return f[x];
	if(x==1||x==2)return f[x] = 1;
	return f[x] = F(x-1)+F(x-2);
} 
*/
int a[maxn];
bool cmp(int a, int b){return a>b;}
int main(){
	/*
	int n; 
	while(cin>>n){
		for(int i = 1; i <= n; i++)cin>>a[i];
		sort(a+1,a+n+1,cmp);
		for(int i = 1; i <= n; i++){
			if(i!=1)cout<<" ";
			cout<<a[i];
		}
		cout<<endl;
	}
	*/
	cout<<"JuShenNiuBi";
	return 0;
}

1023

#include<bits/stdc++.h>
using namespace std;
const int maxn = 1100;
int f[maxn][maxn];
/*
int F(int x){
	if(f[x])return f[x];
	if(x==1||x==2)return f[x] = 1;
	return f[x] = F(x-1)+F(x-2);
} 
*/
int main(){
	for(int i = 1 ; i < 30; i++)f[i][1] = f[1][i] = f[0][i] = 1;
	
	for(int i = 1; i <= 30; i++)
		for(int j = 1; j <= 30; j++)
			if(i>=j)f[i][j] = f[i][j-1]+f[i-j][j];
			else f[i][j] = f[i][j-1];
	int a, b;
	while(cin>>a>>b){
		cout<<f[a][b]<<endl;
	}
	return 0;
}

1024

#include<bits/stdc++.h>
using namespace std;
const int maxn = 1100;
int f[maxn][maxn];
/*
int F(int x){
	if(f[x])return f[x];
	if(x==1||x==2)return f[x] = 1;
	return f[x] = F(x-1)+F(x-2);
} 
*/
int a[maxn];
bool cmp(int a, int b){return a>b;}
int main(){
	int n; 
	while(cin>>n){
		for(int i = 1; i <= n; i++)cin>>a[i];
		sort(a+1,a+n+1,cmp);
		for(int i = 1; i <= n; i++){
			if(i!=1)cout<<" ";
			cout<<a[i];
		}
		cout<<endl;
	}
	return 0;
}

37016

1001

#include<bits/stdc++.h>
using namespace std;
typedef long long LL;
const int maxn = 1100;
map<string,string>ma;
int main(){
	int n, m;
	while(cin>>n>>m){
		for(int i = 1; i <= n; i++){
			string a,b;
			cin>>a>>b;
			ma[a] = b;
		}
		for(int i = 1; i <= m; i++){
			string t;
			cin>>t;
			if(ma.count(t))cout<<ma[t]<<"\n";
			else cout<<"aoaoaonb\n";
		}
	}
	return 0;
}

1002

#include<bits/stdc++.h>
using namespace std;
typedef long long LL;
const int maxn = 1100;
int main(){
	int n; 
	while(cin>>n &&n){
		queue<int>q;
		for(int i = 1; i <= n; i++){
			int x;  cin>>x; q.push(x);
		}
		while(q.size()>1){
			q.pop();
			int t = q.front();
			q.pop();
			q.push(t);
		}
		cout<<q.front()<<endl;
	}
	return 0;
}

1003

#include<bits/stdc++.h>
using namespace std;
typedef long long LL;
int main(){
	//freopen("test.cpp","r",stdin);
	vector<LL>vec;
	LL k, sum = 0;
	while(cin>>k &&k){
		if(k==1){
			LL x;  cin>>x;
			vec.push_back(x);
			sum += x;
		}else if(k==2){
			if(vec.size()==0)cout<<"No money!\n";
			else{
				cout<<vec.back()<<" "<<vec.size()-1<<" "<<sum-vec.back()<<"\n";
				sum -= vec.back();
				vec.pop_back();
			}
		}else{
			cout<<vec.size()<<" "<<sum<<endl;
			vec.clear();
			sum = 0;
		}
	}
	return 0;
}

1004

#include<bits/stdc++.h>
using namespace std;
typedef long long LL;

int main(){
	//freopen("test.cpp","r",stdin);
	int n, m;
	while(cin>>n>>m){
		vector<int>vec[10010];
		for(int i = 1; i <= n; i++){
			int a, b;
			cin>>a>>b;
			vec[a].push_back(b);
		}
		for(int i = 1; i<= m; i++){
			if(vec[i].size()==0)continue;
			sort(vec[i].begin(), vec[i].end());
			if(vec[i].size()%2==1)printf("%.3f\n",vec[i][(vec[i].size()-1)/2]*1.0);
			else printf("%.3f\n",(vec[i][vec[i].size()/2]+vec[i][(vec[i].size()-1)/2])*1.0/2);
		}
	}
	return 0;
}

1005

#include<bits/stdc++.h>
using namespace std;
typedef long long LL;

int main(){
	//freopen("test.cpp","r",stdin);
	int n; 
	while(cin>>n){
		priority_queue<int>q;
		for(int i = 1; i <= n; i++){
			char ch;  cin>>ch;
			if(ch=='Q'){
				int x;  cin>>x;
				q.push(x);
			}else{
				if(q.size()!=0){
					cout<<q.top()<<endl;
					q.pop();
				}
				else cout<<"AK!\n";
			}
		}
	}
	return 0;
}

1006

#include<bits/stdc++.h>
using namespace std;
typedef long long LL;

int main(){
	//freopen("test.cpp","r",stdin);
	int n; 
	while(cin>>n){
		deque<LL>q;
		for(int i = 1; i <= n; i++){
			LL op, x;  cin>>op>>x;
			if(op==0){
				q.push_front(x);
			}else{
				q.push_back(x);
			}
		}
		vector<LL>vec(q.begin(),q.end());
		//sort(vec.begin(),vec.end());
		double ans = 0;
		if(vec.size()%2==1){
			ans = vec[(vec.size()-1)/2]*1.0;
		}else{
			ans = (vec[vec.size()/2]+vec[vec.size()/2-1])/2.0;
		}
		printf("%.3lf\n",ans);
		//if(vec.size()%2==1)printf("%.3f\n",vec[(vec.size()-1)/2]*1.0);
		//else printf("%.3f\n",(vec[vec.size()/2+1]+vec[vec.size()/2])/2.0);
	}
	return 0;
}

1007

#include<bits/stdc++.h>
using namespace std;
typedef long long LL;

int main(){
	//freopen("test.cpp","r",stdin);
	int n;
	while(cin>>n){
		set<string>se;
		for(int i = 1; i <= n; i++){
			string str;  cin>>str;
			se.insert(str);
		}
		cout<<se.size()<<endl;
	}
	return 0;
}

1008

#include<bits/stdc++.h>
using namespace std;
typedef long long LL;

int main(){
	//freopen("test.cpp","r",stdin);
	string s;
	while(cin>>s){
		cout<<count(s.begin(),s.end(),'a')<<endl;
	}
	return 0;
}

1009

#include<bits/stdc++.h>
using namespace std;
typedef long long LL;

int main(){
	//freopen("test.cpp","r",stdin);
	int n;
	while(cin>>n){
		int sum = 0;
		for(int i = 1; i <= n; i++){
			int x; cin>>x; sum+= x;
		}
		printf("%.4lf\n",sum*1.0/n);
	}
	return 0;
}

1010

#include<bits/stdc++.h>
using namespace std;
typedef long long LL;

int main(){
	//freopen("test.cpp","r",stdin);
	int n;
	while(cin>>n){
		int mx = -1, mi = 1e9;
		for(int i = 1; i <= n; i++){
			int x; cin>>x;
			mx = max(x,mx);
			mi = min(x,mi);
		}
		cout<<mx-mi<<endl;
	}
	return 0;
}

1011

#include<bits/stdc++.h>
using namespace std;
typedef long long LL;

int main(){
	//freopen("test.cpp","r",stdin);
	int x;
	while(cin>>x){
		int ans = 0;
		while(x>0){
			ans += x%10;
			x /= 10;
		}
		cout<<ans<<endl;
	}
	return 0;
}

1012

#include<bits/stdc++.h>
using namespace std;
typedef long long LL;

int main(){
	//freopen("test.cpp","r",stdin);
	int n, m;
	while(cin>>n>>m){
		int a[50][50];
		for(int i = 1; i <= n; i++){
			for(int j = 1; j <= m; j++){
				cin>>a[i][j];
			}
		}
		int ans = -1e9;
		for(int i = 1; i <= n; i++){
			for(int j = 1; j <= m; j++){
				for(int r = i; r <= n; r++){
					for(int c = j; c <= m; c++){
						int tmp = 0;
						for(int ii = i; ii <= r; ii++){
							for(int jj = j; jj <= c; jj++){
								tmp += a[ii][jj];
							}
						}
						ans = max(ans,tmp);
					}
				}
			}
		}
		cout<<ans<<endl;
	}
	return 0;
}

1013

#include<bits/stdc++.h>
using namespace std;
typedef long long LL;

int main(){
	//freopen("test.cpp","r",stdin);
	double xa, ya, xb, yb, xc, yc;
	while(cin>>xa>>ya>>xb>>yb>>xc>>yc){
		if(xa==xb){
			if(xb==xc)cout<<"YES\n";
			else cout<<"NO\n";
			continue;
		}
		if(ya==yb){
			if(yb==yc)cout<<"YES\n";
			else cout<<"NO\n";
			continue;
		}
		double k1 = (yb-ya)/(xb-xa);
		double k2 = (yc-ya)/(xc-xa);
		if(abs(k1-k2)<1e-4)printf("YES\n");
		else printf("NO\n");
	}
	return 0;
}

1014

#include<bits/stdc++.h>
using namespace std;
typedef long long LL;

int main(){
	//freopen("test.cpp","r",stdin);
	int n;
	while(cin>>n){
		char a[20][20];
		memset(a,0,sizeof(a));
		int cnt = 'a';
		for(int i = 1; i <= n; i++){
			if(cnt>'z') cnt = 'a';
			a[i][1] = cnt++;
		}
		for(int i = n-1,j=2; i >= 2; i--,j++){
			if(cnt>'z') cnt = 'a';
			a[i][j] = cnt++;
		}
		for(int i = 1; i <= n; i++){
			if(cnt>'z') cnt = 'a';
			a[i][n] = cnt++;
		}
		for(int i = 1; i <= n; i++){
			for(int j =1 ; j<= n; j++){
				if(a[i][j]!=0)printf("%c",a[i][j]);
				else printf(" ");
			}
			cout<<endl;
		}
	}
	return 0;
}

1015

#include<bits/stdc++.h>
using namespace std;
typedef long long LL;

int main(){
	//freopen("test.cpp","r",stdin);
	string s;
	while(cin>>s){
		for(int i = 0 ; i < s.size(); i++){
			if(s[i]>='a'&&s[i]<='z'){
				printf("%c",s[i]-('a'-'A'));
				//cout<<s[i]-('a'-'A');
			}else cout<<s[i];
		}
		cout<<endl;
	}
	return 0;
}

1016

#include<bits/stdc++.h>
using namespace std;
typedef long long LL;

int main(){
	//freopen("test.cpp","r",stdin);
	int n;   //cin>>n;
	string s[110];
	while(cin>>n){
		for(int i = 1; i <= n; i++)cin>>s[i];
		sort(s+1,s+n+1);
		cout<<s[n]<<endl;
	}
	return 0;
}

1017

#include<bits/stdc++.h>
using namespace std;
typedef long long LL;

LL a, n;
LL F(LL x){
	if(x==1)return a;
	return (x % 2 == 0) ? F(x / 2) + 1 : F((x + 1) / 2) * 3 - 2;
}

int main(){
	//freopen("test.cpp","r",stdin);
	while(cin>>a>>n){
		cout<<F(n)<<endl;
	}
	return 0;
}

1018

#include<bits/stdc++.h>
using namespace std;
typedef long long LL;

int main(){
	//freopen("test.cpp","r",stdin);
	string s;
	while(cin>>s){
		for(int i = 1; i <= s.size(); i++){
			if(s.size()%i!=0)continue;
			int ok = 1;
			for(int j = 0; j < s.size(); j++){
				if(s[j]!=s[j%i]){ok=0;break;}
			}
			if(ok){
				cout<<i<<endl;
				break;
			}
		}
	}
	return 0;
}

1019


1020


1021

#include<bits/stdc++.h>
using namespace std;
const int maxn = 100010;
int a[maxn], b[maxn];
int main(){
	int T;  cin>>T;
	while(T--){
		int n, k;
		cin>>n>>k;
		for(int i = 0; i < n; i++)cin>>a[i];
		for(int i = 0; i < n; i++)cin>>b[i];
		int ans = 0;
		for(int i = 0; i < n; i++){
			int tmp = 2;
			tmp += abs(a[i]-b[i]);
			tmp += abs(a[i]-b[(i+1)%n]);
			cout<<tmp<<endl;
			ans += tmp;
		}
		cout<<ans<<endl;
	}
	return 0;
}

1022

#include<bits/stdc++.h>
using namespace std;
int Youxianji(char op){
	if(op=='*'||op=='/')return 2;
	if(op=='+'||op=='-')return 1;
	if(op=='(')return 0;
}
void ToHouzhui(string str, string& ans){
	stack<char>stk;
	ans = "";
	int i =0;
	while(i<str.size()){
		if(str[i]>='0' && str[i]<='9'){
			//ans += str[i];
			int t = 0;
			while(str[i]>='0' && str[i]<='9'){
				t = t*10+str[i]-'0';
				i++;
			}
			ans += to_string(t)+".";
		}else{
			if(stk.empty()){
				stk.push(str[i]);
			}else if(str[i]=='('){
				stk.push(str[i]);
			}else if(str[i]==')'){
				while(stk.top()!='('){
					ans += stk.top();
					stk.pop();
				}
				stk.pop();
			}else{
				while(Youxianji(stk.top())>=Youxianji(str[i])){
					ans += stk.top();
					stk.pop();
					if(stk.empty())break;
				}
				stk.push(str[i]);
			}
			i++;
		}
	}
	while(stk.size()){
		ans += stk.top();
		stk.pop();
	}
}
int culate(string str){
	stack<int>stk;
	int ans = 0, i = 0;
	while(i < str.size()){
		if(str[i]>='0'&&str[i]<='9'){
			//stk.push(str[i]-'0');
			int t = 0;
			while(str[i]!='.'){
				t = t*10+str[i]-'0';
				i++;
				//cout<<t<<endl;
			}
			i++;
			//cout<<t<<endl;
			stk.push(t);
		}else{
			int a = stk.top();  stk.pop();
			int b = stk.top();  stk.pop();
			int tmp;
			if(str[i]=='+')tmp = b+a;
			if(str[i]=='-')tmp = b-a;
			if(str[i]=='*')tmp = b*a;
			if(str[i]=='/')tmp = b/a;
			stk.push(tmp);
			i++;
		}
	}
	return stk.top();
}

int main(){
	string s,t;
	while(cin>>s){
		ToHouzhui(s,t);
		//cout<<t<<endl;
		cout<<culate(t)<<endl;
	}
	return 0;
}

1023

#include<bits/stdc++.h>
using namespace std;
char mp[100][100];
int main(){
	int T;  cin>>T;
	while(T--){
		fill(mp[0],mp[0]+100*100,'.');
		int a, b, c;
		cin>>a>>b>>c;
		//V
		for(int i = b*2+1; i <= (b+c)*2+1; i++){
			for(int j = 1; j <= a*2+1; j++){
				if(i%2==1){
					if(j%2==1){
						mp[i][j] = '+';
					}else{
						mp[i][j] = '-';
					}
				}else{
					if(j%2==1){
						mp[i][j] = '|';
					}
				}
			}
		}
		//H
		for(int i = 1; i <= 2*b; i++){
			for(int j = 2*(b+1)-i; j <= (2*(b+1)-i)+2*a; j++){
				if(i%2==1){
					if(j%2==1){
						mp[i][j] = '+';
					}else{
						mp[i][j] = '-';
					}
				}else{
					if(j%2==0){
						mp[i][j] = '/';
					}
				}
			}
		}
		//W
		for(int j = 2*a+1; j <= (a+b)*2+1; j++){
			for(int i = 2*(a+b+1)-j; i <= (2*(a+b+1)-j)+2*c; i++){
				if(i%2==1){
					if(j%2==1){
						mp[i][j] = '+';
					}
				}else{
					if(j%2==1){
						mp[i][j] = '|';
					}else{
						mp[i][j] = '/';
					}
				}
			}
		}
		//
		for(int i = 1; i <= (b+c)*2+1; i++){
			for(int j = 1; j <= (a+b)*2+1; j++){
				cout<<mp[i][j];
			}
			cout<<endl;
		}
		
	}
	return 0;
}

1024

#include<bits/stdc++.h>
using namespace std;
const int maxn = 1010;
int a[maxn];
int main(){
	int n, m;
	while(cin>>n>>m){
		for(int i = 1; i <= n; i++)cin>>a[i];
		for(int i = 1; i <= m; i++)next_permutation(a+1,a+n+1);
		for(int i = 1; i <= n; i++){
			if(i!=1)cout<<" ";
			cout<<a[i];
		}
		cout<<endl;
	}
	return 0;
}

1025

#include<bits/stdc++.h>
using namespace std;
const int maxn = 1010;
int a[maxn];
int main(){
	printf("Hello World\n");
	return 0;
}

ps.

passowrd:fightingforZUST
已标记关键词 清除标记
相关推荐
©️2020 CSDN 皮肤主题: 技术工厂 设计师:CSDN官方博客 返回首页