栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 软件开发 > 后端开发 > C/C++/C#

CSP 2014-9

C/C++/C# 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

CSP 2014-9

1.相邻数对

#include
#include
#include
#include
using namespace std;
#define N 1010  

int a[N];
int main(){
	int n;
	cin>>n;
	for(int i=0;i>a[i];
	sort(a,a+n);
	long long ans=0;
	for(int i=0;i 

2.画图
直接模拟即可:

#include
#include
#include
#include
using namespace std;
#define N 102 

int a[N][N]={0};
void mm(int x1,int y1,int x2,int y2){
    for(int i=x1;i>n;

    while(n--){
        int x1,x2,y1,y2;
        cin>>x1>>y1>>x2>>y2;
        mm(x1,y1,x2,y2);
    }
    int ans=0;
    for(int i=0;i<=100;i++)
    for(int j=0;j<=100;j++)
    ans+=a[i][j];
    cout< 

3.字符串匹配

#include

using namespace std;

void lower(string &s){
    for(int i=0;i='A'&&s[i]<='Z') 
    s[i]=s[i]-'A'+'a';
}

int main(){
    string h;
    cin>>h;
    int op,n;
    cin>>op>>n;

    if(!op) lower(h);
    for(int i=0;i>st;
        s=st;
        if(!op) lower(s);
        if(s.find(h)!=-1)
        cout< 

用strstr(父串,子串)可以更快的找到子字符串,时间复杂度为o(n),没有找到则返回NULL

#include
#include
using namespace std;

void lower(string &s){
    for(int i=0;i='A'&&s[i]<='Z') 
    s[i]=s[i]-'A'+'a';
}

int main(){
    string h;
    cin>>h;
    int op,n;
    cin>>op>>n;

    if(!op) lower(h);
    for(int i=0;i>st;
        s=st;
        if(!op) lower(s);
        if(strstr(s.c_str(),h.c_str())!=NULL)
        cout< 

4.最优配餐
自己的代码,可以通过CSP官网,不能通过ACWing(超时

#include
#include
#include
using namespace std;

// 首先从栋栋的所有起点开始多源bfs,得到起点到一整张图的距离 
// 枚举客户即可 

struct node{
	int x,y,c;
};
int n,m,k,d;
#define N 1010
int mp[N][N];
int dir[4][2]={0,1,0,-1,-1,0,1,0};
int main(){
	memset(mp,-1,sizeof(mp));
	cin>>n>>m>>k>>d;
	queue q;
	vector user;
	while(m--){
		int x,y;
		cin>>x>>y;
		q.push((node){x,y,0});
	}
	
	while(k--){
		int x,y,c;
		cin>>x>>y>>c;
		user.push_back((node){x,y,c});
	}
	while(d--){
		int x,y;
		cin>>x>>y;
		mp[x][y]=0;
	}
	while(q.size()){
		node top=q.front();
		q.pop();
		
		if(top.x<=0||top.x>n||top.y<=0||top.y>n||mp[top.x][top.y]!=-1) continue;
		mp[top.x][top.y]=top.c++;
		
		for(int i=0;i<4;i++)
		q.push((node){top.x+dir[i][0],top.y+dir[i][1],top.c});
	}
	long long ans=0;
	
	for(int i=0;i 

y总的代码:(明天再整理吧

 
转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/298068.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号