称检测点查询
//#include <bits/stdc++.h> //提交到CCF需要添加万能头文件
#include <iostream>
#include <math.h>
using namespace std;
struct PointD{
int PointN;
double D;
struct PointD* next;
};
int main(){
int x,y,n,xi,yi;
double distance;
struct PointD* p=new struct PointD;
struct PointD* head=p;
struct PointD* preP;
scanf("%d %d %d",&n,&x,&y);
for(int i=0;i<n;++i){
scanf("%d %d",&xi,&yi);
distance=(sqrt(pow(xi-x,2)+pow(yi-y,2)));
p->PointN=i+1;
p->D=distance;
preP=p;
p=p->next=new struct PointD;
}
preP->next=NULL;
//sorting
struct PointD* pre=new struct PointD;
pre->next=head;
for(int i=0;i<3;++i){
int minN=pre->next->PointN;
double minD=pre->next->D;
struct PointD* preMin=pre;
for(struct PointD* temp=pre;temp->next->next;temp=temp->next){
if(temp->next->D < minD){
minN=temp->next->PointN;
minD=temp->next->D;
preMin=temp;
}
else if(temp->next->D == minD){
if(temp->next->PointN < minN){
minN=temp->next->PointN;
minD=temp->next->D;
preMin=temp;
}
}
}
struct PointD* f=preMin->next;
preMin->next=preMin->next->next;
free(f);
cout<<minN<<endl;
}
return 0;
}
风险人群筛查
#include <bits/stdc++.h>
using namespace std;
//boolean: check the point stands in the square or not
bool examine(int xl,int yd,int xr,int yu,int xi,int yi){
if(xi>=xl && yi>=yd && xi<=xr && yi<=yu){
return 1;
}
else{
return 0;
}
}
int main(){
int n,k,t,xl,yd,xr,yu,x,xi,yi;
int whether;int stay=0;int passBy=0;
scanf("%d %d %d %d %d %d %d",&n,&k,&t,&xl,&yd,&xr,&yu);
for(int i=0;i<n;i++){
vector<int> point;
int sum=0;int continuous=0;int isStay=0;
for(int j=0;j<(2*t);j++){
cin>>x;
point.push_back(x);
}
for(int i=0;i<(2*t-1);i=i+2){
xi=point[i];
yi=point[i+1];
//cout<<"xi: "<<xi<<" yi: "<<yi<<endl;
whether=examine(xl,yd,xr,yu,xi,yi);
//cout<<"whether: "<<whether<<endl;
sum += whether;
//cout<<"sum: "<<sum<<endl;
if(whether){
continuous++;
if(continuous>=k){
isStay=1;
}
}
else{
continuous=0;
}
}
if(isStay){
stay++;
//cout<<"stay: "<<stay<<endl;
}
//cout<<"cintinuous: "<<continuous<<endl;
//cout<<"isStay: "<<isStay<<endl;
if(sum>=1){
passBy++;
//cout<<"passBy: "<<passBy<<endl;
}
}
cout<<passBy<<endl;
cout<<stay;
return 0;
}
期末预测之安全指数
#include <iostream>
#include <math.h>
using namespace std;
int main(){
int n,wi,scorei,sum=0;
cin>>n;
if(n<2 || n>pow(10,5)){
return 0;
}
for(int i=0;i<n;i++){
scanf("%d %d",&wi,&scorei);
sum+=wi*scorei;
}
int y=max(0,sum);
cout<<y;
return 0;
}
期末预测之最佳阈值
#include <iostream>
#include <math.h>
#include <vector>
#include <algorithm>
#include <set>
using namespace std;
int main(){
int m; // row
cin>>m;
if(m<2 || m>pow(10,5)){
return 0;
}
vector<int> y;
vector<int> result;
int yi,resulti;
for(int i=0;i<m;++i){
scanf("%d %d",&yi,&resulti);
y.push_back(yi);
result.push_back(resulti);
}
vector<int> B(m);
set<int> temp(y.begin(),y.end());
B.assign(temp.begin(),temp.end());
vector<int> sum(B.size(),0);
for(int i=0;i<B.size();i++){
for(int j=0;j<m;j++){
sum[i] += (y[j]>=B[i] == result[j]);
}
//cout<<sum[i]<<endl; //debug
}
vector<int> sum_sort=sum;
sort(sum_sort.begin(),sum_sort.end());
int sum_max=sum_sort.back();
vector<int> num;
for(int i=0;i<B.size();++i){
if(sum[i]==sum_max){
num.push_back(i);
}
}
/*for(int i=0;i<num.size();i++){
cout<<num[i]<<endl;
}*/
sort(num.begin(),num.end());
int B_best=num.back();
cout<<B[B_best];
return 0;
}