CSP2020-06

 

  CSP202006-1 线性分类器

 

 

 

 

 

 

这次的题出的还是挺有意思的,第一题至少不算是无脑题qwq,至少要学过高中数学??

 1 //
 2 //  main.cpp
 3 //  CSP202006-1 线性分类器
 4 //
 5 //  Created by sylvia on 2021/11/15.
 6 //  Copyright © 2021 apple. All rights reserved.
 7 //
 8 
 9 #include <iostream>
10 #include <math.h>
11 #include <algorithm>
12 #include <string.h>
13 using namespace std;
14 #define M 10000+5
15 struct Type{
16     int x,y;
17     char type;
18 }a[M];
19 int c1,c2,c3,n,m;
20 int judge(int c1,int c2,int c3){
21     char big='c',small='c';
22     int i=1;
23     while (i<=n){
24         if (a[i].x*c2+a[i].y*c3+c1==0) return 0;
25         if (a[i].x*c2+a[i].y*c3+c1>0){
26             if ((big=='c')|| (big==a[i].type))
27                 big=a[i].type;
28             else return 0;
29         }
30         if (a[i].x*c2+a[i].y*c3+c1<0){
31             if ((small=='c')|| (small==a[i].type))
32                 small=a[i].type;
33             else return 0;
34         }
35         i++;
36     }
37     return 1;
38 }
39 int main(){
40     cin>>n>>m;
41     for (int i=1;i<=n;i++){
42         cin>>a[i].x>>a[i].y>>a[i].type;
43     }
44     for (int i=1;i<=m;i++){
45         cin>>c1>>c2>>c3;
46         if(judge(c1,c2,c3)) cout<<"Yes"<<endl; else cout<<"No"<<endl;
47     }
48     return 0;
49     
50     
51 }
View Code

 

  CSP202006-2 稀疏变量

 

 

 

 

 

 第二题也比之前的有意思,至少题干长了些hhhh O(a+b)做法

 1 //
 2 //  main.cpp
 3 //  CSP202006-2 稀疏变量
 4 //
 5 //  Created by sylvia on 2021/11/15.
 6 //  Copyright © 2021 apple. All rights reserved.
 7 //
 8 
 9 #include <iostream>
10 #include <math.h>
11 #include <algorithm>
12 #include <string.h>
13 using namespace std;
14 #define M 500000+5
15 pair<int,int> u[M],v[M];
16 int n,a,b;
17 long long ans;
18 int main(){
19     cin>>n>>a>>b;
20     for (int i=1;i<=a;i++)
21         cin>>u[i].first>>u[i].second;
22     for (int i=1;i<=b;i++)
23          cin>>v[i].first>>v[i].second;
24     int i=1,j=1;
25     while (i<=a&&j<=b){
26         if (u[i].first==v[j].first){
27             ans+=u[i].second*v[j].second;
28             i++;
29             j++;
30         }
31         while (u[i].first>v[j].first&&i<=a&&j<=b) j++;
32         while (u[i].first<v[j].first&&i<=a&&j<=b) i++;
33     }
34     cout<<ans<<endl;
35     return 0;
36 }

 

posted @ 2021-11-15 18:03  Sylvia_lee  阅读(42)  评论(0编辑  收藏  举报