【LGR-149-Div.3】洛谷基础赛 #2 & qw Round -1 赛后总结
整体评价
说是普及组难度但感觉比普及组简单一些,因为我普及组从来没有上过300
T1 100 pts
签到题,没什么好说的
#include <iostream>
#include <cstdio>
using namespace std;
int main() {
int a, b, c, d, e;
cin >> a >> b >> c >> d >> e;
int sum = a + b + c + d + e;
if(sum <= 99) cout << "Gray" << endl;
else if (sum <= 119) cout << "Blue" << endl;
else if (sum <= 169) cout << "Green" << endl;
else if (sum <= 229) cout << "Orange" << endl;
else cout << "Red" << endl;
return 0;
}
T2 100pts
找最左边最后边的就可以了
#include <iostream>
using namespace std;
const int maxn = 1e5 + 5;
int a[maxn];
int main() {
int n;
cin >> n;
int ans = 0;
int left, right;
left = right = 0;
for(int i = 1; i <= n; i++) {
cin >> a[i];
}
for(int i = 1; i <= n; i++) {
if(a[i] == 1) {
left = i;
break;
}
}
for(int i = n; i >= 0 ;i --) {
if(a[i] == 1) {
right = i;
break;
}
}
if(left != 0 && right != 0)cout << right - left + 1 << endl;
else cout << 0 << endl;
return 0;
}
T3 100pts
T3两个小时的时候才做出来,第一次做的时候情况没有考虑完整只得了40分,但是后面提交的时候因为STL的选择不对导致TLE,最后把STL由STL换成了queue才通过了这道题。
这道题就是模拟题吧。
#include <iostream>
#include <queue>
#include <map>
#include <set> //用了好多STL尝试,最终还是决定用queue
#include <vector> //本来说STL过不了我就手打,最终还是过了
#include <algorithm>
#include <unordered_set>
using namespace std;
int n;
queue <string> que;
queue <string> playing;
map <string, string> mp;
map <string, int> number;
int main() {
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
cin >> n;
while(n--) {
string op;
cin >> op;
if(op == "start") {
while(!playing.empty()) {
que.push(playing.front());
mp[playing.front()] = "-Watting";
playing.pop();
}
if(que.empty()){
cout << "Error" << endl;
continue;
}
for(int i = 1, success = 0; success < 2 && !que.empty(); i++) {
if(number[que.front()] > 1 || mp[que.front()] == "") {
number[que.front()]--;
que.pop();
continue;
}
mp[que.front()] = "-Playing";
success++;
playing.push(que.front());
cout << que.front() << " ";
que.pop();
}
cout << endl;
}
else if(op == "arrive") {
string ar;
cin >> ar;
if(mp[ar] == "-Watting" || mp[ar] == "-Playing") {
cout << "Error" << endl;
continue;
}
mp[ar] = "-Watting";
number[ar]++;
que.push(ar);
cout << "OK" << endl;
}
else if(op == "leave") {
string le;
cin >> le;
if(mp[le] == "-Playing" || mp[le] == "") {
cout << "Error" << endl;
continue;
}
mp[le] = "";
cout << "OK" << endl;
}
}
return 0;
}
T4 50pts
这道题两种特殊情况一共20pts, 加上了30分的暴力,按理来说暴力应该是能拿60pts,但是我的暴力写挂了,只拿了50
~~话说两个小时我这个蒟蒻都写不出来,我就是个废柴~~
正解应该是二分,但是我实在是没有看出来,看来二分还是不是很熟悉
“`cpp
// U318099 pay
// https://www.luogu.com.cn/problem/U318099?contestId=123900
include
include
include
include <limits.h>
using namespace std;
const int maxn = 1e6 + 10;
define int long long
int n, m;
int a[maxn];
int b[maxn];
long long f[maxn];
int Max = -1;
bool check() {
for(int i = 1; i <= n; i++) {
if(f[i] < a[i]) return false;
}
return true;
}
namespace LS {
void Main() {
for(int i = Max / m/就是因为这里除以了一个m我才卡到50分/; i <= INT_MAX; i++) {
for(int j = 1;j <= m; j++) {
for(int q = max((long long)1, b[j] – i + 1); q <= min(n, b[j] + i – 1); q++) {
f[q] += max(i – abs(b[j] – q), (long long)0);
}
}
if(check()) {
cout << i << endl;
return;
}
for(int i = 1; i <= n; i++) f[i] = 0;
}
}
}
namespace N1 {
void Main() {
cout << a[1] << endl;
}
}
namespace M1 {
void Main() {
int ans = 0;
for(int i = 1; i <= n; i++) {
a[i] += abs(i – b[1]);
ans = max(ans, a[i]);
}
cout << ans << endl;
}
}
signed main()
{
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
cin >> n;
cin >> m;
for(int i = 1; i <= n; i++) {
cin >> a[i];
Max = max(Max, a[i]);
}
for(int i = 1; i <= m; i++) {
cin >> b[i];
}
if(n == 1) {
N1::Main();
return 0;
}
if(m == 1) {
M1::Main();
return 0;
}
LS::Main();
return 0;
}
“