团体程序设计天梯赛 L1-046~L1-050

L1-046

思路:

我们模拟一下手写除法即可

代码:

#include<bits/stdc++.h>

using namespace std;

int main() {
	int x, ans = 1, n = 1;
	cin >> x;
	while(ans < x) ans = ans * 10 + 1, ++n;
	while(true){
		cout << ans / x;
		if(ans % x == 0) break;
		ans = (ans % x) * 10 + 1;
		++n;	
	}
	cout << ' ' << n;
	return 0;
}

L1-047

思路:

if判断下即可

代码:

#include<bits/stdc++.h>

using namespace std;

int main() {
	int n;
	cin >> n;
	while(n--){
		string s;
		int x, y;
		cin >> s >> x >> y;
		if(x < 15 || x > 20 || y < 50 || y > 70) cout << s << '\n';	
	}
	return 0;
}

L1-048

思路:

学会矩阵乘法即可

代码:

#include<bits/stdc++.h>

using namespace std;

typedef vector<int> vec;
typedef vector<vec> mat;

void out(mat & m){
	for(int i = 0; i < m.size(); i++){
		putchar('\n');
		for(int j = 0; j < m[i].size(); j++){
			if(j) putchar(' ');
			cout << m[i][j];	
		}
	}
}
inline void read(mat & m){
	int r, c;
	cin >> r >> c;
	m = mat(r, vec(c));
	for(int i = 0; i < r; i++)
	for(int j = 0; j < c; j++)
	cin >> m[i][j];
}
void solve(mat & a, mat & b){
	if(a[0].size() != b.size()) { printf("Error: %d != %d", a[0].size(), b.size()), exit(0); }
	cout << a.size() << ' ' << b[0].size();
	mat res(a.size(), vec(b[0].size()));
	for(int i = 0; i < a.size(); ++i)
	for(int j = 0; j < a[0].size(); ++j)
	for(int k = 0; k < b[0].size(); ++k)
	res[i][k] += a[i][j] * b[j][k];
	out(res);
}

int main() {
	mat a, b;
	read(a);
	read(b);
	solve(a, b);
	return 0;
}

L1-049

思路:

模拟一下座位分配过程,注意所有高校分配完后只剩一所高校时,应该间隔开来

代码:

#include<bits/stdc++.h>

using namespace std;

const int maxn = 123;
vector<int> v[maxn];
int num[maxn];

void out(int & x){
	for(int i = 0; i < v[x].size(); i++){
		if(i % 10) putchar(' ');
		cout << v[x][i];
		if((i + 1) % 10 == 0) putchar('\n');
	}
}

int main() {
	int n, tot = 0, no = 0, rcd = -1;    //num of stu & record of seat
	cin >> n;
	for(int i = 1; i <= n; i++){
		cin >> num[i];
		num[i] *= 10;
		tot += num[i];
	}
	while(tot){
		for(int i = 1; i <= n; i++){
			if(num[i] == 0) continue;
			if(rcd == i) ++no;
			v[i].push_back(++no);
			--tot; --num[i];
			rcd = i;	
		}
	}
	for(int i = 1; i <= n; i++){
		printf("#%d\n", i);
		out(i);
	}
	return 0;
}

L1-050

思路:

我们把这题想象成26进制就很好做了

代码:

#include<bits/stdc++.h>

using namespace std;

int main() {
	int l, n;
	cin >> l >> n;
	string s = "";
	int num = pow(26, l);
	num -= n;
	while(s.length() != l){
		s += num % 26 + 'a';
		num /= 26;
	}
	reverse(s.begin(), s.end());
	cout << s;
	return 0;
}
发布了280 篇原创文章 · 获赞 7 · 访问量 6704

猜你喜欢

转载自blog.csdn.net/qq_45228537/article/details/104009361
今日推荐