202006-1(未解决 错误代码)
#include
#include
using namespace std;
struct point{
int x;
int y;
char type;
point(int x,int y,char type):x(x),y(y),type(type){}
};
struct line{
int a,b,c;
line(int a,int b,int c):a(a),b(b),c©{}
};
int main()
{
int n,m;
cin>>n>>m;
vector points_a;
vector points_b;
vector lines;
for(int i=0;i<n;i++)
{
int px,py;
char ptype;
cin>>px>>py>>ptype;
if(ptype==‘A’)
{
points_a.push_back(point(px,py,ptype));
}
else
points_b.push_back(point(px,py,ptype));
}
for(int j=n;j<n+m;j++)
{ int c0,c1,c2; cin>>c0>>c1>>c2; lines.push_back(lines(c0,c1,c2)); } for (int i = 0; i < m; i++) { bool flg = true; //划定标定值 long long standard = points_a[0].x * lines[i].a + points_a[0].y * lines[i].b + lines[i].c; //判断A类点 for (int j = 1; j < points_a.size(); j++) { long long temp = points_a[j].x * lines[i].a + points_a[j].y * lines[i].b + lines[i].c; if (temp * standard < 0) { cout << “No” << endl; flg = false; break; } else continue; } if (!flg) continue;//The line cannot be separated, verify the next one
//Judging B points
for (int j = 0; j <points_b.size(); j++) { long long temp = points_b[j].x * lines[i].a + points_b[j].y * lines [i].b + lines[i].c; if (temp * standard> 0) { cout << “No” << endl; flg = false; break; } } if (!flg) continue; //The Straight lines cannot be separated, verify the next cout << "Yes" << endl; } return 0; } correct code (non-original) //C++ //15ms 544KB
#include
#include
using namespace std;
struct point {
int x;
int y;
};
struct line {
int a, b, c;
};
int main() {
int n, m;
vector points_a;
vector points_b;
vector
cin >> n >> m;
//读入点
for (int i = 0; i < n; i++) {
point temp;
char type;
cin >> temp.x >> temp.y >> type;
if (type == ‘A’)
points_a.push_back(temp);
else points_b.push_back(temp);
}
//读入直线
for (int i = 0; i < m; i++) {
line temp;
cin >> temp.c >> temp.a >> temp.b;
lines.push_back(temp);
}
//判定
for (int i = 0; i < m; i++) {
bool flg = true;
//划定标定值
long long standard = points_a[0].x * lines[i].a + points_a[0].y * lines[i].b + lines[i].c;
//判断A类点
for (int j = 1; j < points_a.size(); j++) {
long long temp = points_a[j].x * lines[i].a + points_a[j].y * lines[i].b + lines[i].c;
if (temp * standard < 0) {
cout << "No" << endl;
flg = false;
break;
}
else continue;
}
if (!flg) continue; //该直线不能分隔,验证下一条
//判断B类点
for (int j = 0; j < points_b.size(); j++) {
long long temp = points_b[j].x * lines[i].a + points_b[j].y * lines[i].b + lines[i].c;
if (temp * standard > 0) {
cout << "No" << endl;
flg = false;
break;
}
}
if (!flg) continue; //该直线不能分隔,验证下一条
cout << "Yes" << endl;
}
return 0;
}
202006-2 (Do not use for loop timeout)
#include
#include
using namespace std;
const int max_ = 5*100000+5;
int array1_id[max_],array1_value[max_];
int array2_id[max_],array2_value[max_];
int main()
{ int n,a,b; //n-dimensional vector, a and b are the number of non-zero values of the two vectors respectively int i,j; long long sum; //sum inner product int id,val; cin>>n>>a>>b; //Initialize sum = 0;
//输入数据
for(i=0;i<a;i++)
{
cin>>id>>val;
array1_id[i] = id;
array1_value[i] = val;
}
for(i=0;i<b;i++)
{
cin>>id>>val;
array2_id[i] = id;
array2_value[i] = val;
}
i = 0,j = 0;
while(i<a && j<b)
{
if(array1_id[i] == array2_id[j])
{
sum += array1_value[i]*array2_value[j];
i++;
j++;
}
if(array1_id[i] > array2_id[j]) j++;
if(array1_id[i] < array2_id[j]) i++;
}
cout<<sum;
return 0;
}