CCF刷题-0912

啊报了9月19的CSP考试!!!
呜呜呜,题目越刷越感觉难…

这两天在看acwing的课,y总好厉害!!!

202006-1 线性分类器
害,在CCF上提交100分,在acwing上测试过不了,估计是数据问题哈哈哈哈,CCF数据水

#include<iostream>
#include<sstream>
#include<cstring>
#include<string>
#include<cstdio>
#include<vector>
#include<algorithm>
using namespace std;

#define x first
#define y second

typedef long long LL;

struct node{
	int x;
	int y;
};

vector<node> d1,d2;

int main(){   
	int n,m;
	cin>>n>>m;
	node temp;
	char cc;
	for(int i=0;i<n;i++){
		cin>>temp.x>>temp.y>>cc;
		if(cc=='A')	d1.push_back(temp);
		else d2.push_back(temp);
	}
	int a,b,c;
	LL flag1,flag2;
	LL t1,t2;
	for(int i=0;i<m;i++){
		cin>>a>>b>>c;
		int f=1;
		flag1=a+b*d1[0].x+c*d1[0].y;
		flag2=a+b*d2[0].x+c*d2[0].y;
		
		if((LL)flag1*flag2>=0){
			cout<<"No"<<endl;
			continue;
		}
		for(int j=1;j<d1.size();j++){
			t1=a+b*d1[j].x+c*d1[j].y;
			if((LL)t1*flag1<=0){
				f=0;
				break;
			}
		}
		for(int j=1;j<d2.size()&&f;j++){
			t2=a+b*d2[j].x+c*d2[j].y;
			if((LL)t2*flag2<=0){
				f=0;
				break;
			}
		}
		if(f)	cout<<"Yes"<<endl;
		else cout<<"No"<<endl;
	}
	
	
    return 0;
}

好了,刚刚又尝试了一遍,发现数据全部改为long long ,acwing上就能过了


#define x first
#define y second

typedef long long LL;

struct node{
	LL x;
	LL y;
};

vector<node> d1,d2;

int main(){   
	int n,m;
	cin>>n>>m;
	node temp;
	char cc;
	for(int i=0;i<n;i++){
		cin>>temp.x>>temp.y>>cc;
		if(cc=='A')	d1.push_back(temp);
		else d2.push_back(temp);
	}
	int a,b,c;
	LL flag1,flag2;
	LL t1,t2;
	for(int i=0;i<m;i++){
		cin>>a>>b>>c;
		int f=1;
		flag1=(a+b*d1[0].x+c*d1[0].y)>0?1:-1;
		flag2=(a+b*d2[0].x+c*d2[0].y)>0?1:-1;
		
		if(flag1==flag2){
			cout<<"No"<<endl;
			continue;
		}
		for(int j=1;j<d1.size();j++){
			t1=(a+b*d1[j].x+c*d1[j].y)>0?1:-1;
			if(t1!=flag1){
				f=0;
				break;
			}
		}
		for(int j=1;j<d2.size()&&f;j++){
			t2=(a+b*d2[j].x+c*d2[j].y)>0?1:-1;
			if(t2!=flag2){
				f=0;
				break;
			}
		}
		if(f)	cout<<"Yes"<<endl;
		else cout<<"No"<<endl;
	}
	
	
    return 0;
}

202006-2 稀疏向量

#include<iostream>
#include<sstream>
#include<cstring>
#include<string>
#include<cstdio>
#include<vector>
#include<algorithm>
using namespace std;
const int N=110,INF=1e9;
int n,a,b;
struct node{
	int index;
	int value;
};

vector<node> d1,d2;

int main(){   
	cin>>n>>a>>b;
	node temp;
	for(int i=0;i<a;i++){
		cin>>temp.index>>temp.value;
		d1.push_back(temp);
	}
	for(int i=0;i<b;i++){
		cin>>temp.index>>temp.value;
		d2.push_back(temp);
	}
	
	long long sum=0;
	for(int i=0,j=0;i<a&&j<b;i++){
		while(j<b&&d1[i].index>d2[j].index){
			j++;
		}
		if(j<b&&d1[i].index==d2[j].index){
			sum+=(long long)d1[i].value*d2[j].value;
		}
	}
	cout<<sum;
	
    return 0;
}

202006-3 MarkDwon渲染器
这题好恶心啊。
跟着视频敲了一遍代码。

#include<iostream>
#include<sstream>
#include<cstring>
#include<string>
#include<cstdio>
#include<vector>
#include<algorithm>
using namespace std;

#define x first
#define y second

typedef long long LL;

const int N=20*1024*1024+10;
char str[N];
vector<string> strs;

bool check_blank(string &s){
	for(int i=0;i<s.size();i++){
		char c=s[i];
		if(c!=' ')	return false;
	}
	return true;
}

int get(string &s){
	if(check_blank(s))	return 0;
	if(s.size()>=2&&s[0]=='*'&&s[1]==' ')	return 1;
	if(s.size()>=2&&s[0]==' '&&s[1]==' ')	return 2;
	return 3;
	
}

string trim(string s){
	int i=0,j=s.size()-1;
	while(i<=j&&s[i]==' ')	i++;
	while(i<=j&&s[j]==' ')	j--;
	if(i>j) return "";
	return s.substr(i,j-i+1);
} 

int wc(string &s,int w){
	int res=0;
	for(int i=0;i<s.size();i++){
		if(s[i]==' ')	continue;
		int j=i+1;
		while(j<s.size()&&j-i+1<=w)	j++;
		res++;
		i=j-1;
	}
	return max(res,1);
}

int main(){   
	int w;
	scanf("%d",&w);
	getchar();
	while(fgets(str,N,stdin)){
		strs.push_back(str);
		strs.back().pop_back();  // 删除回车
	}
	
	int r=-1,last=0;
	for(int i=0;i<strs.size();){
		int t=get(strs[i]);
		if(t==0)	i++,last=2;
		else if(t==1){
			if(last!=1)	r++;
			last=1;
			string line=trim(strs[i].substr(2));
			i++;
			while(i<strs.size()){
				if(get(strs[i])==2){
					line+=' '+trim(strs[i].substr(2));
					i++;
				}
				else break;
			}
			r+=wc(line,w-3);
		}else{
			r++;
			last=0;
			string line=trim(strs[i]);
			i++;
			while(i<strs.size()){
				int t=get(strs[i]);
				if(t==2||t==3){
					line+=' '+trim(strs[i]);
					i++;
				}
				else break;
			}
			r+=wc(line,w);
		}
	}
	printf("%d\n",r);
    return 0;
}

202006-4 1246
不会写,跟着y总敲部分代码,还只得了4分,懒得找错误了。
以后再攻第4题

typedef long long LL;

const int N=14,MOD=998244353;

int n;
string S;
int id[100];

vector<int> vers{1,2,4,6,16,26,41,42,44,46,61,62,64,66};
vector<vector<int>> g{
	{2},{4},{1,6,16},{6, 4, 64},{26},{46},{62},{64},{61},{66},{42},{44},{41},{46}
};
int tr[N][N];

void init(){
	memset(id,-1,sizeof(id));
	for(int i=0;i<N;i++)	id[vers[i]]=i;
	for(int i=0;i<N;i++){
		for(auto x:g[i]){
			tr[i][id[x]]++;
		}
	}
}


void mul(int c[][N],int a[][N],int b[][N]){
	static int tmp[N][N];
	memset(tmp,0,sizeof(tmp));
	for(int i=0;i<N;i++){
		for(int j=0;j<N;j++){
			for(int k=0;k<N;k++){
				tmp[i][j]=(tmp[i][j]+(LL)a[i][k]*b[j][k])%MOD;
			}
			
		}
	}
	memcpy(c,tmp,sizeof tmp);
}

int qmi(int k,int id){
	if(id==-1)	return 0;
	int res[N][N]={0},w[N][N];
	memcpy(w,tr,sizeof w);
	res[0][0]=1;
	while(k){
		if(k&1)	mul(res,res,w);
		mul(w,w,w);
		k>>=1;
	}
	return res[0][id];
}

int main(){   
	init();
	cin>>n>>S;
	cout<<qmi(n,id[stoi(S)])<<endl;
    return 0;
}

202009-1 称检测点查询
总是不记得qsort的用法。。sort也搞不清。。。

#include<iostream>
#include<algorithm>
#include<string>

using namespace std;

struct node{
	int x,y,index;
	long long dis;
}d[210];

int cmp(const void *a,const void *b){
	node *c=(node *)a;
	node *d=(node *)b;
	if(c->dis!=d->dis)	return c->dis -d->dis;
	else return c->index-d->index;
}


int main(){
	int n,x,y;
	cin>>n>>x>>y;
	for(int i=0;i<n;i++){
		cin>>d[i].x>>d[i].y;
		d[i].dis=(d[i].x-x)*(d[i].x-x)+(d[i].y-y)*(d[i].y-y);
		d[i].index=i;
	}
	node temp;
	qsort(d,n,sizeof(node),cmp);
	for(int i=0;i<3;i++)	cout<<d[i].index+1<<endl;
	
	return 0;
} 

202009-2 风险人群检测

很奇怪,acwing上能过,ccf上过不了,找不出错误…

#include<iostream>
#include<algorithm>
#include<string>

using namespace std;

struct node{
	int x,y;
}d[1010];

int n,k,t,xl,yd,xr,yu;

int check(int x,int y){
	if(x>=xl&&x<=xr&&y>=yd&&y<=yu)	return 1;
	else return 0;
}


int main(){
	
	cin>>n>>k>>t>>xl>>yd>>xr>>yu;
	int pass=0,stay=0;
	
	for(int i=0;i<n;i++){//逐行分析 
		int flag=0;
		for(int j=0;j<t;j++){
			cin>>d[j].x>>d[j].y;
			if(check(d[j].x,d[j].y))	flag=1;
		}
		
		if(flag)	pass++;
		
		int count=0;
		for(int j=0;j<t;j++){
			if(count>=k){
				stay++;
				break;
			}
			
			if(check(d[j].x,d[j].y))	count++;
			else count=0;
		}
	}

	cout<<pass<<endl<<stay<<endl;
	return 0;
} 

真的不懂,改成下面的代码,就过了,我还是不知道错误在哪。

#include<iostream>
#include<algorithm>
#include<string>

using namespace std;

struct node{
	int x,y;
}d[1010];

int n,k,t,xl,yd,xr,yu;

int check(int x,int y){
	if(x>=xl&&x<=xr&&y>=yd&&y<=yu)	return 1;
	else return 0;
}


int main(){
	
	cin>>n>>k>>t>>xl>>yd>>xr>>yu;
	int pass=0,stay=0;
	
	for(int i=0;i<n;i++){//逐行分析 
		int flag1=0,flag2=0,count=0;
		for(int j=0;j<t;j++){
			cin>>d[j].x>>d[j].y;
			if(check(d[j].x,d[j].y)){
				flag1=1;
				count++;
				if(count>=k)	flag2=1;
			}
			else count=0;
		}
		
		if(flag1)	pass++;
		if(flag2)	stay++;
		
		
	}

	cout<<pass<<endl<<stay<<endl;
	return 0;
} 
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值