回收站选址
这道题是第一次提交满分,之前是因为数值涉及太大,我不知道怎么存储以及判断会省时一些,就一直没做;这次做用到了STL,也算是做了这么多第三题回看第二题的一些简便吧

#include<bits/stdc++.h>
using namespace std;
typedef pair<int,int> PII;
set<PII> se;
int res[10];
int main()
{
ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
int n; cin >> n;
for(int i = 0;i < n;i ++){
int x, y; cin >> x >> y;
se.insert({
x, y});
}
int idx[] = {
-1, 1, 0, 0, -1, -1, 1, 1};
int idy[] = {
0, 0, -1, 1, -1, 1, -1, 1};
for(auto point : se){
int x = point.first, y = point.second;
bool flag = true;
for(int i = 0;i < 4 && flag;i ++){
//看是否符合要求
int dx = x + idx[i];
int dy = y + idy[i];
if(!se.count({
dx, dy})) {
flag = false; break; }
}
if(flag){
//符合要求的基础上,统计得分
int cnt = 0;
for(int i = 4;i < 8;i ++){
int dx = x + idx[i];
int dy = y + idy[i];
if(se.count({
dx, dy})) cnt ++;
}
res[cnt] ++;
}
}
for(int i = 0;i <= 4;i ++){
cout << res[i] << endl;
}
return 0;
}
化学方程式
第一把官网提交是80分,acwing通过的答案是 9 / 11;先贴出80分的初始代码:
#include<bits/stdc++.h>
#define key first
#define value second
using namespace std;
typedef pair<string, int> PSI;
int to_int(string str)
{
stringstream ssin(str);
int x;
ssin >> x;
return x;
}
bool upper(char ch)
{
if(ch >= 'A' && ch <= 'Z') return true;
return false;
}
bool lower(char ch)
{
if(ch >= 'a' && ch <= 'z') return true;
return false;
}
bool number(char ch)
{
if(ch >= '0' && ch <= '9') return true;
return false;
}
unordered_map<string, int> cal(string str)
{
unordered_map<string, int> res;
vector<string> expr;
for(int i = 0, j = 0; i < str.size()

文章讲述了作者在C++编程中解决回收站选址问题的过程,使用了STL集合和优化算法处理字符串,尤其是嵌套括号的计数,以及从80分到满分的思路转变。
最低0.47元/天 解锁文章
715

被折叠的 条评论
为什么被折叠?



