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)个要互送礼物的朋友,郭铮鹏要确定每个人送出的钱比收到的多多少. 在这一个问题中,每个人都准备了一些钱来送礼物,而这些钱将会被平均分给那些将收到他的礼物的人 ...
随机推荐
- MVC + EFCore 项目实战 - 数仓管理系统8 - 数据源管理下--数据源预览
上篇我们完成了数据源保存功能,并顺便看了保存后的数据源列表展示功能. 本篇我们开始开发预览功能,用户预览主要步骤: 1.点击数据源卡片预览按钮 2.查看数据源包含的表 3.点击表名,预览表中数据 ...
- macOS 遇到 svnadmin无法使用的情况
首先,我在网上查了很多资料,大多数开发者都是表明了mac内置svn,然后直接使用svnadmin来创建仓库,但是我用命令行敲入svnadmin却显示找不到svnadmin.最开始,有个资料说用whic ...
- 学习python的几个资料网站
菜鸟教程 https://www.runoob.com/python3/python3-tutorial.html https://www.runoob.com/python/python-tutor ...
- python基础day5_元组
元祖---只读列表,可循环查询,可切片 儿子不能改,孙子可能可以改.增加(主要看要操作的是属于列表还是元组) tu = (1,2,3,'alex',[2,3,4,'taibai'],'egon') t ...
- mysql8.0以上版本修改密码问题记录
参考链接: https://blog.csdn.net/qq_27820551/article/details/101488430 https://blog.csdn.net/mukouping82/ ...
- Java 添加、删除、格式化Word中的图片
本文介绍使用Spire.Cloud.SDK for Java提供的ImagesApi接口来操作Word中的图片.具体可通过addImage()方法添加图片.deleteImage()方法删除图片.up ...
- fastjson JSON.toJavaObject() 实体类首字母大写属性无法解析问题
fastjson JSON.toJavaObject() 实体类首字母大写属性无法解析问题
- 铁大树洞APP视频讲解和原型演示
首先放上我们团队视频讲解演示的视频:https://v.youku.com/v_show/id_XNDYyMzA3MTgzNg==.html 团队名称:超能陆战队 团队成员:刘梦鑫(队长) 段行行 徐 ...
- Netty(一):的入门使用。
Netty的入门基本使用流程代码,不做具体分析.使用版本为Netty 4.x版本. 服务端调用示例: 绑定端口号为8080端口 package com.cllover; import com.sun. ...
- 20、Java 泛型
1.晓之以理,动之以码 学Java就是很上头哦,一来直接三连问!!! 什么是泛型?为什么要用泛型?泛型怎么用? 当然泛型在Java中有很重要的一个地位,在面向对象编程以及在各种设计模式中有非常广泛的应 ...