第1题:角色吻合度 60%
#include <bits/stdc++.h>
#include <iomanip>
#define LL long long
using namespace std;
const int maxn = 1e7 + 5;
const double eps = 1e-4;
struct ST {
LL login, logout;
LL online;
int roleid;
};
bool cmp(ST a, ST b) {
return a.roleid < b.roleid;
}
ST newRole[maxn];
ST role[maxn];
int main()
{
string type;
string data;
for (int i = 0; i < maxn; i++) {
role[i].logout = -1;
}
while (cin >> data) {
int len = data.size();
LL time = 0, roleid = 0;
string type = "";
bool flag1 = true, flag2 = true, flag3 = false;
for (int i = 0; i < len; i++) {
if (data[i] == '[') continue;
if (data[i] == ']') {
if (!flag1) flag2 = false;
flag1 = false;
continue;
}
if (flag1) time = time * 10 + data[i] - '0';
if (data[i] == '\"' && flag3) flag3 = false;
if ((i > 2 && data[i - 1] == '\"' && data[i - 2] == ':') || flag3) {
flag3 = true;
roleid = roleid * 10 + data[i] - '0';
}
if (!flag1 && flag2) type += data[i];
}
//cout << time << ' ' << type << ' ' <<roleid << endl;
if (type == "login") role[roleid].login = time;
else if (type == "logout") role[roleid].logout = time;
}
int cnt = 0;
for (int i = 0; i < maxn; i++) {
if (role[i].logout != -1) {
newRole[cnt].login = role[i].login;
newRole[cnt].logout = role[i].logout;
newRole[cnt].online = role[i].logout - role[i].login;
newRole[cnt++].roleid = i;
}
}
sort(newRole, newRole + cnt, cmp);
int ans1[maxn], ans2[maxn], dex = 0;
set<int> ans;
LL tmp = -1;
for (int i = 0; i < cnt; i++) {
for (int j = i + 1; j < cnt; j++) {
LL a = max(newRole[i].login, newRole[j].login);
LL b = min(newRole[i].logout, newRole[j].logout);
LL val = (b - a) * 2.0 / (newRole[i].online + newRole[j].online);
if (val > tmp) {
tmp = val;
dex = 0;
ans.clear();
}
if (abs(tmp - val) < eps) {
ans.insert(newRole[i].roleid);
ans.insert(newRole[j].roleid);
ans1[dex] = newRole[i].roleid;
ans2[dex++] = newRole[j].roleid;
}
}
}
for (int i : ans) cout << i << endl;
return 0;
}
第2题:左手规则走迷宫 0%
#include <bits/stdc++.h>
#include <iomanip>
#define LL long long
using namespace std;
const int maxn = 1e6 + 5;
int dir[4][2] = {{-1, 0}, {0, 1}, {1, 0}, {0, -1}};
int main()
{
int t;
cin >> t;
while (t--) {
int w, h;
cin >> w >> h;
char mat[45][45];
int sx, sy, direct;
for (int i = 0; i < w; i++) {
for (int j = 0; j < h; j++) {
cin >> mat[i][j];
if (mat[i][j] == 'S') {
sx = i;
sy = j;
if (sx == 0) direct = 2;
else if (sy == 0) direct = 1;
else if (sx == w - 1) direct = 0;
else direct = 3;
}
}
}
int cnt = 0;
//cout << sx << ' ' << sy << endl;
//cout << direct << endl;
while (1) {
int nx = sx + dir[direct][0], ny = sy + dir[direct][1];
//cout << nx << ' ' << ny << endl;
if (nx < 0 || nx >= w || ny < 0 || ny >= h || mat[nx][ny] == '#') direct = (direct + 1) % 4;
else if (mat[nx][ny] == 'E') {
cout << cnt << endl;
break;
}
else {
sx = nx;
sy = ny;
cnt++;
direct = (direct - 1) % 4;
cout << nx << ' ' << ny << endl;
}
}
}
return 0;
}
/*
2
5 5
#####
#...#
#...#
#.#.#
#E#S#
9 5
#########
#.#.#.#.#
S.......E
#.#.#.#.#
#########
7
17
*/
第3题:根据SQL语句输出查询结果 100%
#include <bits/stdc++.h>
#include <iomanip>
#define LL long long
using namespace std;
const int maxn = 1e7 + 5;
struct ST {
LL id, age, height, weight;
LL id1, id2;
double val;
};
const double eps = 1e-9;
bool cmp(ST a, ST b) {
if (a.id1 == b.id1) {
if (abs(a.val - b.val) < eps) return a.id2 < b.id2;
return a.val < b.val;
}
return a.id1 < b.id1;
}
LL compute(LL a, LL b)
{
LL ans = (a - b)*(a - b);
return ans;
}
ST table[maxn];
ST newTable[maxn];
int main()
{
int n;
cin >> n;
for (int i = 0; i < n; i++) {
int id, age, height, weight;
cin >> id >> age >> height >> weight;
table[i].id = id;
table[i].age = age;
table[i].height = height;
table[i].weight = weight;
}
int cnt = 0;
set<int> s;
for (int i = 0; i < n; i++) {
for (int j = 0; j < n; j++) {
if (table[i].id != table[j].id) {
double val = sqrt(compute(table[i].age, table[j].age) + compute(table[i].height, table[j].height) + compute(table[i].weight, table[j].weight));
if (val < 20) {
s.insert(table[i].id);
newTable[cnt].id1 = table[i].id;
newTable[cnt].id2 = table[j].id;
newTable[cnt++].val = val;
}
}
}
}
sort(newTable, newTable + cnt, cmp);
int vis[maxn]; // group by id1
memset(vis, 0, sizeof(vis));
for (int i = 0; i < cnt; i++) {
if (!vis[newTable[i].id1] && s.find(newTable[i].id1) != s.end()) {
vis[newTable[i].id1] = 1;
cout << newTable[i].id1 << ' ' << newTable[i].id2 << ' ';
printf("%.2f\n", newTable[i].val);
}
}
return 0;
}
#网易##网易互娱##题解#