L1-046
Ideas:
we can simulate what handwriting division
of code:
#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
Ideas:
the determination can if
codes:
#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
Idea:
learn to matrix multiplication
Code:
#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
Ideas:
Analog my seat assignment process, pay attention to all colleges and universities after only a college assignment, should be spaced
Code:
#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
Thinking:
we think of this title is very good to do a 26-ary
Code:
#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;
}