ACM集训第一次积分赛赛前复习+day4
不知不觉4天过去了,我们迎来了我们第一次积分赛,赛前的四天我们学了以下知识点吧:
day 1、排序
之前一直想用qsort,但是总是写不明白,STL的sort()可以说是很方便了。
先写一个最基础的数组排序
bool compare(int a,int b)
{
return a<b; //升序排列,如果改为return a>b,则为降序
}#include <algorithm>
int main()
{
int a[]={,,,,,,,,,},i;
for(i=;i<;i++)
cout<<a[i]<<endl;
sort(a,a+,compare);
for(i=;i<;i++)
cout<<a[i]<<endl;
return ;
}
还有就是稍微复杂点的结构体排序
#include <iostream>
#include <vector>
#include <algorithm> using namespace std; typedef struct example
{
int elem1;
int elem2;
}example; /*这个comparison函数很重要.如果希望升序排序,就是"<",降序排列就是">"号,这样便于直观记忆.如果希望用elem2作为比较标准
就把elem1改为elem2,这样结构体就以elem2为比较标准排序了.*/ bool comparison(example a,example b){
return a.elem1<b.elem1;
} int main()
{
int N;
fin>>N; vector<example> array(N); for(int i=;i<N;i++)
{
fin>>array[i].elem1>>array[i].elem2;
} sort(array.begin(),array.end(),comparison); for(int i=;i<N;i++)
{
cout<<array[i].elem1<<" "<<array[i].elem2<<endl;
}
return ;
}
day 2、BIT冬训-模拟&枚举
模拟和枚举个人感觉算是比较简单的了,因为没有算法,所以数据范围不会很大,也不用担心TLE,但是给我印象很深的就是迷宫题和五子棋题,挺复杂的。
这里贴一个五子棋的题
Alice and Bob play 5-in-a-row game. They have a playing field of size 10 × 10. In turns they put either crosses or noughts, one at a time. Alice puts crosses and Bob puts noughts.
In current match they have made some turns and now it's Alice's turn. She wonders if she can put cross in such empty cell that she wins immediately.
Alice wins if some crosses in the field form line of length not smaller than 5. This line can be horizontal, vertical and diagonal.
Input
You are given matrix 10 × 10 (10 lines of 10 characters each) with capital Latin letters 'X' being a cross, letters 'O' being a nought and '.' being an empty cell. The number of 'X' cells is equal to the number of 'O' cells and there is at least one of each type. There is at least one empty cell.
It is guaranteed that in the current arrangement nobody has still won.
Output
Print 'YES' if it's possible for Alice to win in one turn by putting cross in some empty cell. Otherwise print 'NO'.
Example
XX.XX.....
.....OOOO.
..........
..........
..........
..........
..........
..........
..........
..........
YES
XXOXX.....
OO.O......
..........
..........
..........
..........
..........
..........
..........
..........
NO
代码如下
#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <cstdlib>
#include <string>
#include <map>
#include <vector>
#include <set>
#include <queue>
using namespace std;char mp[][];
int main()
{
for (int i = ; i < ; ++i)
{
scanf("%s",mp[i]);
} for (int i = ; i < ; ++i)
{
for (int j = ; j < ; ++j)
{
if (mp[i][j] == '.')
{
int s=;
s = ;
for (int k = j - ; k >= ; --k)
{
if (mp[i][k] == 'X')
{
++s;
if (s==)
{
printf("YES\n");
return ;
}
}
else break;
}
for (int k = j + ; k < ; ++k)
{
if (mp[i][k] == 'X')
{
++s;
if (s==)
{
printf("YES\n");
return ;
}
}
else break;
}
s = ;
for (int k = i - ; k >= ; --k)
{
if (mp[k][j] == 'X')
{
++s;
if (s==)
{
printf("YES\n");
return ;
}
}
else break;
}
for (int k = i + ; k < ; ++k)
{
if (mp[k][j] == 'X')
{
++s;
if (s==)
{
printf("YES\n");
return ;
}
}
else break;
}
s = ;
for (int k = i - , q = j - ; k >= && q >= ; --k, --q)
{
if (mp[k][q] == 'X')
{
++s;
if (s==)
{
printf("YES\n");
return ;
}
}
else break;
} for (int k = i + , q = j + ; k < && q < ; ++k, ++q)
{
if (mp[k][q] == 'X')
{
++s;
if (s==)
{
printf("YES\n");
return ;
}
}
else break;
}
s = ;
for (int k = i + , q = j - ; k < && q >= ; ++k, --q)
{
if (mp[k][q] == 'X')
{
++s;
if (s==)
{
printf("YES\n");
return ;
}
}
else break;
}
// 右上
for (int k = i - , q = j + ; k >= && q < ; --k, ++q)
{
if (mp[k][q] == 'X')
{
++s;
if (s==)
{
printf("YES\n");
return ;
}
}
else break;
}
}
}
}
printf("NO\n");
return ;
}
这题的思路是看别人的,不知道贴上来算不算抄袭、
3、可以看昨天的博客
4、简单数据结构
其实今天挺复杂的,而且也是有点填鸭了,所谓的讲就是把栈,队列,堆,树这些东西怎么定义告诉了我们,并没有告诉我们有什么性质,或者有什么意义,30分钟不到讲了四个东西。我不是吐槽今天讲课的小姐姐,因为这四天都是这样,但是今天的比较困难,就有点说不过去了。不过老实说以后讲课时间会保障1个小时,看看吧。
(1)先说说栈
我也像讲课那样吧,简单的说一下用法。
#include<iostream>
#include<stack>
using namespace std; int main()
{
stack <int>stk;
//入栈
for(int i=;i<;i++){
stk.push(i);
}
cout<<"栈的大小:"<<stk.size()<<endl;
while(!stk.empty())
{
cout<<stk.top()<<endl;
stk.pop();
}
cout<<"栈的大小:"<<stk.size()<<endl;
return ;
}
(2)、C++ Queues(队列)、Priority Queues(优先队列)
C++队列是一种容器适配器,它给予程序员一种先进先出(FIFO)的数据结构。
1.back() 返回一个引用,指向最后一个元素
2.empty() 如果队列空则返回真
3.front() 返回第一个元素
4.pop() 删除第一个元素
5.push() 在末尾加入一个元素
6.size() 返回队列中元素的个数
队列可以用线性表(list)或双向队列(deque)来实现(注意vector container 不能用来实现queue,因为vector 没有成员函数pop_front!):
queue<list<int>> q1;
queue<deque<int>> q2;
其成员函数有“判空(empty)” 、“尺寸(Size)” 、“首元(front)” 、“尾元(backt)” 、“加入队列(push)” 、“弹出队列(pop)”等操作。
int main()
{
queue<int> q;
q.push();
q.push();
printf("%d\n",q.front());
q.pop();
}
C++ Priority Queues(优先队列)
C++优先队列类似队列,但是在这个数据结构中的元素按照一定的断言排列有序。
1.empty() 如果优先队列为空,则返回真
2.pop() 删除第一个元素
3.push() 加入一个元素
4.size() 返回优先队列中拥有的元素的个数
5.top() 返回优先队列中有最高优先级的元素
优先级队列可以用向量(vector)或双向队列(deque)来实现(注意list container 不能用来实现queue,因为list 的迭代器不是任意存取iterator,而pop 中用到堆排序时是要求randomaccess iterator 的!):
priority_queue<vector<int>, less<int>> pq1; // 使用递增less<int>函数对象排序
priority_queue<deque<int>, greater<int>> pq2; // 使用递减greater<int>函数对象排序
其成员函数有“判空(empty)” 、“尺寸(Size)” 、“栈顶元素(top)” 、“压栈(push)” 、“弹栈(pop)”等。
#include <iostream>
#include <queue>
using namespace std; class T {
public:
int x, y, z;
T(int a, int b, int c):x(a), y(b), z(c)
{
}
};
bool operator < (const T &t1, const T &t2)
{
return t1.z < t2.z; // 按照z的顺序来决定t1和t2的顺序
}
main()
{
priority_queue<T> q;
q.push(T(,,));
q.push(T(,,));
q.push(T(,,));
q.push(T(,,));
while (!q.empty())
{
T t = q.top();
q.pop();
cout << t.x << " " << t.y << " " << t.z << endl;
}
return ;
}
输出结果为(注意是按照z的顺序从大到小出队的):
3 3 6
2 2 5
1 5 4
4 4 3
#include <iostream>
#include <queue>
using namespace std;
class T
{
public:
int x, y, z;
T(int a, int b, int c):x(a), y(b), z(c)
{
}
};
bool operator > (const T &t1, const T &t2)
{
return t1.z > t2.z;
}
main()
{
priority_queue<T, vector<T>, greater<T> > q;
q.push(T(,,));
q.push(T(,,));
q.push(T(,,));
q.push(T(,,));
while (!q.empty())
{
T t = q.top();
q.pop();
cout << t.x << " " << t.y << " " << t.z << endl;
}
return ;
}
输出结果为:
4 4 3
1 5 4
2 2 5
3 3 6
如果我们把第一个例子中的比较运算符重载为: bool operator < (const T &t1, const T &t2) { return t1.z > t2.z; // 按照z的顺序来决定t1和t2的顺序} 则第一个例子的程序会得到和第二个例子的程序相同的输出结果。
目前主要学的就这么多了,感觉题目已经很难很难了。
以上均为不规范转载。。。因为我还没有完全掌握。
ACM集训第一次积分赛赛前复习+day4的更多相关文章
- 2018.10.19浪在ACM 集训队第一次测试赛
2018.10.19浪在ACM 集训队第一次测试赛 待参考资料: [1]:https://blog.csdn.net/XLno_name/article/details/78559973?utm_so ...
- yzm10的ACM集训小感
7月30号,ACM集训进行了两周,一切都已on the right way.这时的我适时地从题海中探出头,其实除了刷题,也该写点什么来总结下过去.首先,在第一周里,我学习了数据结构,知道了STL这么一 ...
- 【系列】关于NJUPT电赛自控方向第一次积分赛的总结
本人是NJUPT电子科学与技术专业大一摸鱼狗一枚.本博客旨在总结与分享个人准备电赛所学知识,同时也是为了防止遗忘,锻炼写文章的能力.目前电赛方向为自控方向.主要研究方向为单片机.图像处理.自动控制相关 ...
- ACM集训
2019-07-18 09:06:10 emmm.... 昨天5个小时做了一道题,心情复杂,不着急慢慢来 Ivan recently bought a detective book. The book ...
- ACM集训的Day3 B。。。盲目搜索之DFS。。。
milk 一.题目描述: gzp有三个容量分别是A,B,C升的桶,A,B,C分别是三个从1到20的整数, 最初,A和B桶都是空的,而C桶是装满牛奶的.有时,农民把牛奶从一个桶倒到 另一个桶中,直到被灌 ...
- ACM集训的1B。。。。黑色星期五。。。。2333333
题目: 印象中有好多个13号是星期五,13号在星期五比在其他日子少吗?为了回答这个问题,写一个程序,要求计算每个月的十三号落在周一到周日的次数.给出N年的一个周期,要求计算1900年1月1日至1900 ...
- ACM集训的Training Day 3的A题。。。
A. 等差数列 一.题目描述: 一个等差数列是一个能表示成a, a+b, a+2b,..., a+nb (n=0,1,2,3,...)的数列. 在这个问题中a是一个非负的整数,b是正整数.写一个程序来 ...
- ACM集训的第。。。诶~不知道第几题=.=
题目: 郭铮鹏认为排序是一种很频繁的计算任务,所以他考虑了一个简单的问题:现在最多只有三值的排序问题.一个实际的例子是,当我们给某项竞赛的优胜者按金银铜牌排序的时候.在这个任务中可能的值只有三种1,2 ...
- ACM集训的第一题
对于一群NP(2<=NP<=10)个要互送礼物的朋友,郭铮鹏要确定每个人送出的钱比收到的多多少. 在这一个问题中,每个人都准备了一些钱来送礼物,而这些钱将会被平均分给那些将收到他的礼物的人 ...
随机推荐
- jenkins初学部分笔记网站
https://www.cnblogs.com/wfd360/p/11314697.html 自动化部署详细教程 https://blog.csdn.net/weixin_41948075/artic ...
- Kali小技巧
说明:此方法适用于Debian.Ubuntu等带apt工具的操作系统. sudo apt-get autoremove --purge 软件名 # 命令&参数解释: # sudo--获取 ro ...
- PHP date_sub() 函数
------------恢复内容开始------------ 实例 从 2013 年 3 月 15 日减去 40 天: <?php$date=date_create("2013-03- ...
- 基于Python+Requests+Pytest+YAML+Allure实现接口自动化
本项目实现接口自动化的技术选型:Python+Requests+Pytest+YAML+Allure ,主要是针对之前开发的一个接口项目来进行学习,通过 Python+Requests 来发送和处理H ...
- 【NOI2001】方程的解数 题解(dfs+哈希)
题目描述 已知一个方程 k1*x1^p1+k2*x2^p2……+kn*xn^pn=0. 求解的个数.其中1<=x<=150,1<=p<=6; 答案在int范围内 输入格式 第一 ...
- 如何用Keil MDK5创建新项目
1.安装相应软件 2.创建与Build项目 创建项目 下载与调试— ST-Link
- 利用Jsoup爬取新冠疫情数据并存至数据库
需要用到的jar包(用来爬取的jsoup,htmlunit-2.37.0-bin以及连接数据库中的mysql.jar) 链接:https://pan.baidu.com/s/1VlylWmlhjd8K ...
- 使用HttpClient 发送 GET、POST(FormData、Raw)、PUT、Delete请求及文件上传
httpclient4.3.6 package org.caeit.cloud.dev.util; import java.io.File; import java.io.IOException; i ...
- Jupyter PPT
安装 pip install jupyter pip install RISE jupyter-nbextension install rise --py --sys-prefix jupyter-n ...
- Coders' Legacy 2020 题解
目录 Chef vs Doof Doof on Cartesian Doof fires Brackets Jeremy gets a gift Unique Substring Perry lear ...