【LGR-154-Div.4】洛谷入门赛 #15 赛后总结
整体评价
以我的水平就只能做做入门赛了,其他的比赛根本提不上劲。
Debug速度太慢导致题目没有做完。
T1 443 pts (500 pts)
考试的时候迟到了十分钟。
第一题还是很简单一个顺序结构就可解决问题
#include <iostream>
using namespace std;
int a, b, c, d;
int main() {
cin >> a >> b >> c >> d;
int sum = a + b + c + d;
if(sum < 51) {
cout << "Rabbit wins" << endl;
}
else {
cout << "Rabbit lose" << endl;
}
return 0;
}
T2 562 pts (700 pts)
用枚举即可解决问题
#include <iostream>
#include <cstdio>
using namespace std;
int sx, sy, cx, cy, mx, my;
int fx[8] = {-1, -2, -2, -1, 1, 2, 2, 1};
int fy[8] = {-2, -1, 1, 2, 2, 1, -1, -2};
bool check(int x,int y) {
int sum = 0;
for(int i = 0; i < 8; i++) {
int nx = fx[i] + x;
int ny = fy[i] + y;
if((nx == sx && ny == sy) || (nx == cx && ny == cy)) sum++;
if(sum == 2) {
return true;
}
}
return false;
}
int main() {
cin >> sx >> sy >> cx >> cy >> mx >> my;
for(int i = 0; i < 8; i++) {
int nx = fx[i] + mx;
int ny = fy[i] + my;
if(check(nx, ny)) {
cout << "Yes";
return 0;
}
}
cout << "No" << endl;
return 0;
}
T3 772 pts (900pts)
一个找规律,加上一个STL map即可解决问题
#include <iostream>
#include <map>
using namespace std;
map<int,int> M;
int n;
int main() {
for(int i = 1; i <= 6; i += 2) {
M[i] = i + 1;
M[i + 1] = i;
}
cin >> n;
int ans = 0;
for(int i = 1, op; i <= n; i++) {
cin >> op;
if(i == n) {
ans += 21 - M[op];
}
else {
ans += 21 - M[op] - op;
}
}
cout << ans << endl;
return 0;
}
T4 681 pts (1100pts)
暴力加上一个存放Max的数组即可
#include <iostream>
#include <algorithm>
#include <limits.h>
using namespace std;
const int maxn = 1e6 + 5;
typedef long long ll;
#define int long long
int n, c;
int a[maxn], Max[maxn];
signed main() {
cin >> n >> c;
Max[0] = 0;
for(int i = 1; i <= n; i++) {
cin >> a[i];
Max[i] = max(Max[i - 1], a[i]);
}
ll ansval = LLONG_MAX;
int ansindex;
for(int k = 0; k <= n; k++) {
ll t = Max[k] + c * (n - k);
if(t < ansval) {
ansval = t;
ansindex = k;
}
}
cout << ansindex << " " << ansval << endl;
return 0;
}
T5 852 pts (1300 pts)
Map 即可轻松解决
#include <iostream>
#include <map>
using namespace std;
int n, m;
map <int, int> score;
int main() {
cin >> n >> m;
int vacant = 0;
for(int i = 1, kkksc03; i <= n; i++){
cin >> kkksc03;
score[kkksc03] = -1;
}
for(int i = 1, x, y; i <= m; i++) {
cin >> x >> y;
score[x] = y;
}
int ans = 0;
for(auto i = score.begin(); i != score.end(); i++) {
if(i->second < 60) ans++;
if(i->second == -1) vacant ++;
}
cout << vacant << "\n" << ans << "\n";
return 0;
}
T6 713 pts (1300 pts)
就是这道题目把我卡住了,检查了很久,结果发现是数组开小了
看来如果一道题不是爆0应该先检查数据类型,数组是不是开小了,像这种一般你的思路是对的,只不过是实现挂了
#include <iostream>
#include <vector>
using namespace std;
const int maxn = 500 * 500 + 5; //就是这里的问题,之前写成500 + 5,没有考虑到地图是二维的QAQ
int n, m, N, M;
/*
vector <int> mapH[maxn];//雄性 横向
vector <int> mapS[maxn];//ts 纵向
*/
int xF[maxn], yF[maxn];//雌性
int xM[maxn], yM[maxn];//xiong
char map[505][505];
int main(){
cin >> n >> m >> N >> M;
int cnt = 1;
int cnt2 = 1;
for(int i = 1; i <= n; i++)
for(int j = 1; j <= m; j++) {
cin >> map[i][j];
if(map[i][j] == 'F') {
xF[cnt] = i;
yF[cnt++] = j;
}
if(map[i][j] == 'M') {
xM[cnt2] = i;
yM[cnt2++] = j;
}
}
int sum = 0;
for(int i = 1; i <= cnt; i++) {
int Run = 0;
int x, y;
x = xF[i];
y = yF[i];
while(map[x - 1][y] != 'M' && x - 1 >= 1)
x--;
if(x == 1) Run++;
x = xF[i];
y = yF[i];
while(map[x + 1][y] != 'M' && x + 1 <= n )
x++;
if(x == n) Run++;
x = xF[i];
y = yF[i];
while(map[x][y - 1] != 'M' && y - 1 >= 1)
y--;
if(y == 1) Run++;
x = xF[i];
y = yF[i];
while(map[x][y + 1] != 'M' && y + 1 <= m)
y++;
if(y == m) Run++;
x = xF[i];
y = yF[i];
if(Run >= 3)
sum++;
}
for(int i = 1; i <= cnt2; i++) {
int Run = 0;
int x, y;
x = xM[i];
y = yM[i];
while(map[x - 1][y] != 'F' && x - 1 >= 1)
x--;
if(x == 1) Run++;
x = xM[i];
y = yM[i];
while(map[x + 1][y] != 'F' && x + 1 <= n)
x++;
if(x == n) Run++;
x = xM[i];
y = yM[i];
while(map[x][y - 1] != 'F' && y - 1 >= 1)
y--;
if(y == 1) Run++;
x = xM[i];
y = yM[i];
while(map[x][y + 1] != 'F' && y + 1 <= m)
y++;
if(y == m) Run++;
x = xM[i];
y = yM[i];
if(Run >= 3)
sum++;
}
cout << sum << endl;
return 0;
}
T7 694 pts (1700 pts)
也是STL map 解决问题
#include <iostream>
#include <algorithm>
#include <cstring>
#include <vector>
#include <map>
using namespace std;
map<string, string> name;
int main() {
int n, m, l;
cin >> n >> m >> l;
for(int i = 1; i <= n; i++) {
string Input;
cin >> Input;
name[Input] = Input;
}
for(int i = 1; i <= m; i++) {
string Input;
cin >> Input;
name.erase(Input);
}
for(int i = 1; i <= l; i++) {
string Input;
cin >> Input;
name[Input] = Input;
}
vector <string> ls;
for(auto i = name.begin(); i != name.end(); i++) {
ls.push_back(i->second);
}
sort(ls.begin(), ls.end());
for(int i = 0; i < ls.size(); i++){
cout << ls[i] << endl;
}
return 0;
}
T8 0 pts (2000 pts)
这道题在世界这么短的情况下做是没有意义的,于是我就跳到了T9
T9 750pts (1500pts)
这道题只看了第一个程序,爆int了
#include <bits/stdc++.h>
using namespace std;
int main() {
int n, k;
cin >> n >> k;
if (k == n || k == 0) {
cout << "0 0" << endl;
return 0;
}
cout << "1 ";
if (k * 3 <= n)//就是这里爆掉了
cout << 2 * k << endl;
else
cout << n - k << endl;
return 0;
}
总结