第十二届CSP总结
第二次参加CSP 前一次CSP还是去年年初
从通知到准备也就一个礼拜准备,大概看了一下往年的题型:
第一题:水题
第二题:一般都是考点逻辑各种if else嵌套 然后加点排序
今年卡了我的是一个结构体排序
好久没做了果然有点生疏啊
附上一段代码~~~
#include<iostream>
#include<stdio.h>
#include<stdlib.h>
#include<math.h>
#include<algorithm>
using namespace std;
struct node{
int s;
int number;
int e;
};
bool cmp(node a,node b){
if(a.s<b.s) return true;
else if(a.s==b.s&&a.e<b.e) return true;
return false;
}
int main(){
int n;
cin>>n;
int a,b;
node no[5];
for(int i=0;i<n;i++){
cin>>a>>b;
no[i].s = a;
no[i].e = b;
no[i].number = i;
}
sort(no,no+n,cmp);
for(int i=0;i<n;i++){
cout<<no[i].number<<" ";
}
}
第三题:一般都是String类的操作或者大型模拟题 叫你模拟json存储,模拟文件目录,模拟系统权限 然而我并没有打完!!!最后交了一个半成品。。。
OK!附上string的操作函数:
# =,assign() //赋以新值
# swap() //交换连个字符串的内容
# += ,append(),push_back() //在尾部添加字符
# insert() //插入字符
例:str.insert(6,str1); 在6的位置插入str1
str.insert(6,str2,13,4) 在str 第6的位置插入str2第13后的4个字符
# erase() //橡皮擦~删除字符
# clear() 删除全部字符
# replace() //替换字符
+ 串联字符串
# == != < <= >= > compare() //比较字符串
# size() length() 字符串数量
# empty() //判空
# substr() 返回某个子字符串
例:str2 = str.substr(0,10) str2就是str前十个字符串
# compare()
例:string s= ("abcd");
s.compare(0,2,s,2,2); 用“ab”和“cd”比较
s.compare(1,2,"bcx",2) 用“bc”和“bc”比较
# find()
rfind()
find_first_of()
find_last_of()
find_first_not_of()
find_last_not_of()
说明:第一个参数是被搜索的对象
第二个参数是string内的搜索起点索引(可有可无)
第三个参数是搜索的字符格式(可有可无)
注意:返回是第一个字符的索引 没有找到则返回String::npos
第四题:纯算法题 有最短路(dijikstra算法,spfa算法) ,dp动态规划,bfs,dfs,spfa
第五题:一般不看 如果有时间 看一眼暴力做一下
哎!一句话 重在参与 明年再来!