#include
using namespace std;
int main() {
int n, m, x, y, v0, v1, v2;
char c;
scanf("%d%d", &n, &m);
vector>> v;
while (n--) {
scanf("%d%d %c", &x, &y, &c);
v.emplace_back(make_pair(c, make_pair(x, y)));
}
while (m--) {
scanf("%d%d%d", &v0, &v1, &v2);
unordered_map m1, m2;
for (auto it:v)
v0 + v1 * it.second.first + v2 * it.second.second > 0 ? m1[it.first]++ : m2[it.first]++;
printf((m1['A'] == 0 || m1['B'] == 0) && (m2['A'] == 0 || m2['B'] == 0) ? "Yes\n" : "No\n");
}
return 0;
}
注意整除的地方,和变量考虑long long
#include
using namespace std;
struct Node {
int x, y;
char c;
};
int main() {
int n, m;
scanf("%d%d", &n, &m);
vector v;
while (n--) {
Node obj;
scanf("%d%d %c", &obj.x, &obj.y, &obj.c);
v.emplace_back(obj);
}
while (m--) {
int v0, v1, v2;
scanf("%d%d%d", &v0, &v1, &v2);
unordered_map m1, m2;
m1['A'] = 0, m1['B'] = 0, m2['A'] = 0, m2['B'] = 0;
if (v0 != 0 && v1 == 0 && v2 != 0) {
int tempY = floor(-1.0 * v0 / v2);
for (int i = 0; i < v.size(); i++) {
int y = v[i].y;
if (y > tempY)
m1[v[i].c]++;
else
m2[v[i].c]++;
}
} else if (v0 != 0 && v1 != 0 && v2 == 0) {
int tempX = floor(-1.0 * v0 / v1);
for (int i = 0; i < v.size(); i++) {
int x = v[i].x;
if (x > tempX)
m1[v[i].c]++;
else
m2[v[i].c]++;
}
} else
for (int i = 0; i < v.size(); i++) {
int x = v[i].x, y = v[i].y;
long long tempY = floor(-1.0 * (v0 + v1 * x) / v2);
if (y > tempY)
m1[v[i].c]++;
else
m2[v[i].c]++;
}
if ((m1['A'] == 0 || m1['B'] == 0) && (m2['A'] == 0 || m2['B'] == 0))
printf("Yes\n");
else
printf("No\n");
}
return 0;
}
注意存储结果的变量需要用long long
#include
using namespace std;
int main() {
int n, a, b, index, value;
long long total = 0;
scanf("%d%d%d", &n, &a, &b);
vector> v1, v2;
while (a--) {
scanf("%d%d", &index, &value);
v1.emplace_back(make_pair(index, value));
}
while (b--) {
scanf("%d%d", &index, &value);
v2.emplace_back(make_pair(index, value));
}
for (int i = 0, j = 0; i < v1.size() && j < v2.size();)
if (v1[i].first > v2[j].first)
j++;
else if (v1[i].first < v2[j].first)
i++;
else
total += v1[i++].second * v2[j++].second;
printf("%lld\n", total);
return 0;
}