@w616561153
2020-06-28T09:27:09.000000Z
字数 3133
阅读 363
ccf题解
题解
//1805036 <13100928923> <王恪楠> 报数 03-09 13:46 660B C0X 正确 100 15ms 524.0KB
#include <bits/stdc++.h>
using namespace std;
queue<int> q;
int vis[50];
bool is_seven(int x) //判断是否是需要跳过的数.
{
if(x % 7 == 0)
return 1;
while(x){
if(x % 10 == 7)
return 1;
x /= 10;
}
return 0;
}
int main()
{
int n;
scanf("%d", &n);
q.push(1); //用类似约瑟夫环的做法,循环报数.
q.push(2);
q.push(3);
q.push(4);
int cnt = 0, i = 0;
while(cnt != n){
i ++;
int head = q.front();
q.pop();
q.push(head);
if(is_seven(i)){
vis[head] ++;
continue;
}
cnt ++;
}
for(int i = 1; i <= 4; i ++)
printf("%d\n", vis[i]);
return 0;
}
//1805061 <13100928923> <王恪楠> 回收站选址 03-09 14:06 1.352KB C0X 正确 100 15ms 848.0KB
#include <bits/stdc++.h>
#define fi first
#define se second
using namespace std;
typedef pair<int, int> Pii;
vector<Pii> v;
map<Pii, int> vis; //主要是用map记录下每个点是否有垃圾站.
int cnt[50];
int next_1[4][2] = {1, 0, -1, 0, 0, 1, 0, -1};
int next_2[4][2] = {1, 1, 1, -1, -1, 1, -1, -1};
inline int read()
{
int res = 0, f = 1;
char ch;
ch = getchar();
while(48 > ch || ch > 57){
if(ch == '-')
f = -1;
ch = getchar();
}
while(48 <= ch && ch <= 57){
res = (res << 3) + (res << 1) + ch - 48;
ch = getchar();
}
return f * res;
}
int main()
{
int n;
n = read();
for(int i = 1; i <= n; i ++){
int tx, ty;
tx = read(), ty = read();
v.push_back(Pii(tx, ty));
vis[Pii(tx, ty)] = 1;
}
for(int i = 0; i < v.size(); i ++){
int x = v[i].fi, y = v[i].se;
int flag = 0;
for(int j = 0; j < 4; j ++){
int tx = x + next_1[j][0], ty = y + next_1[j][1];
if(!vis[Pii(tx, ty)])
flag = 1;
}
if(flag)
continue;
int score = 0;
for(int j = 0; j < 4; j ++){
int tx = x + next_2[j][0], ty = y + next_2[j][1];
if(vis[Pii(tx, ty)])
score ++;
}
cnt[score] ++;
}
for(int i = 0; i < 5; i ++)
printf("%d\n", cnt[i]);
return 0;
}
#include <bits/stdc++.h>
#define fi first
#define se second
using namespace std;
typedef pair<int, int> Pii;
map<string, int> vis;
vector<string> split(const string &s, const char &oprt)
{
vector<string> res;
string tmp;
for(int i = 0; i < s.length(); i ++){
if(s[i] != oprt)
tmp += s[i];
else{
if(!tmp.empty())
res.push_back(tmp);
tmp.clear();
}
}
if(!tmp.empty())
res.push_back(tmp);
return res;
}
Pii num(int start, const string &s)
{
int res = 0;
for(int i = start; i < s.length(); i ++){
if(isdigit(s[i]))
res = res * 10 + s[i] - 48;
else
return Pii(res, i - 1);
}
}
void chemical_formula(string s, int flag)
{
stack<string> s1, s2;
map<string, int> vis0[50];
int id = 0;
for(int i = 0; i < s.length(); i ++){
if(s[i] != ')'){
string tmp = " ";
tmp[0] = s[i];
if(s[i] == '('){
s1.push(tmp);
id ++;
}
else{
if('a' <= s[i + 1] && s[i + 1] <= 'z'){
tmp += s[i + 1];
i = i + 1;
}
if(isdigit(s[i + 1])){
Pii p = num(i + 1, s);
vis0[id][tmp] += flag * p.fi;
i = p.se;
}
else
vis0[id][tmp] += flag;
s1.push(tmp);
}
}
else{
int tmp = 1;
if(i + 1 < s.length() && isdigit(s[i + 1])){
Pii p = num(i + 1, s);
tmp = p.fi;
i = p.se;
}
for(map<string, int> :: iterator it = vis0[id].begin(); it != vis0[id].end(); it ++){
vis0[id - 1][it -> fi] += it -> se * tmp;
}
vis0[id].clear();
id --;
}
}
for(map<string, int> :: iterator it = vis0[id].begin(); it != vis0[id].end(); it ++)
vis[it -> fi] += it -> se;
return ;
}
void _find(string s0, int flag)
{
vector<string> v = split(s0, '+');
for(int i = 0; i < v.size(); i ++){
string s = v[i];
if(!isdigit(s[0]))
chemical_formula("(" + s + ")", flag);
else{
int cnt = 0;
for(int j = 0; j < s.length(); j ++){
if(isdigit(s[j])){
cnt = cnt * 10 + s[j] - 48;
}
else{
s = s.substr(j);
break;
}
}
chemical_formula("(" + s + ")", flag * cnt);
}
}
return;
}
int main()
{
int n;
scanf("%d", &n);
while(n --){
string s;
cin >> s;
vis.clear();
vector<string> v = split(s, '=');
_find(v[0], 1);
_find(v[1], -1);
int flag = 0;
for(map<string, int> :: iterator it = vis.begin(); it != vis.end(); it ++){
if(it -> second)
flag = 1;
}
if(!flag)
printf("Y\n");
else
printf("N\n");
}
return 0;
}