CCF CSP 202006

1-线性分类器

  • 利用 A x + B y + C Ax+By+C Ax+By+C的值判断在直线的哪一侧
#include<iostream>
#include<algorithm>
#include<string>
using namespace std;
int x[1010],y[1010],n,m,theta0,theta1,theta2;
bool t,flag;
int judge(int _x,int _y){
	return theta0+theta1*_x+theta2*_y;	
}
char type[110]; 
int main(){
	cin>>n>>m;
	for(int i=1;i<=n;i++){
		cin>>x[i]>>y[i]>>type[i];
	}
	for(int i=1;i<=m;i++){
		cin>>theta0>>theta1>>theta2;
		flag=true;		
		t= (type[1]=='A'&&judge(x[1],y[1])>0||
		type[1]=='B'&&judge(x[1],y[1])<0);	
		for(int j=2;j<=n;j++){
			flag= 
			t==(type[j]=='A'&&judge(x[j],y[j])>0||
		type[j]=='B'&&judge(x[j],y[j])<0);
			if(!flag){
				cout<<"No"<<endl;
				break;
			}
		}		
		if(flag) cout<<"Yes"<<endl;
	}
	return 0; 
} 

2-稀疏向量

  • 双指针法
  • 用scanf
#include<iostream>
#include<algorithm>
#include<cstdio>
const int maxn=5e5+10;
using namespace std;
struct p{
	int index,value;
};
int n,a,b,c1,c2;
p u[maxn],v[maxn];
long long ans;
int main(){
	scanf("%d%d%d",&n,&a,&b);
	for(int i=0;i<a;i++){
		scanf("%d%d",&u[i].index,&u[i].value);	
	}
	for(int i=0;i<b;i++){
		scanf("%d%d",&v[i].index,&v[i].value);
	}
	c1=0,c2=0;
	while(c1<a&&c2<b){		
		if(u[c1].index<v[c2].index) c1++;
		else if(u[c1].index==v[c2].index){
			ans+=u[c1].value*v[c2].value;
			c1++;c2++;
		} 
		else c2++;
	}
	cout<<ans<<endl;
} 
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值