今天内写了几个题,学了一下高数,学了点新东西
下面是总结
示例1
输入
5 2 1 5 3 4
5 2 1 5 3 4
输出
5 4 3 1 2
5 4 3 1 2
说明
2入栈;1入栈;5入栈;5出栈;3入栈;4入栈;4出栈;3出栈;1出栈;2出栈
看懂题目不难 唯一的难点就是出栈方式的实现,利用排列(1-N都有)
设置一个为n的最大值 保证尽量是字典序 用一个数组记录已经入栈元素
当前元素等于最大值立即出栈 最大值-1 直到最大值(会改变)没有入栈过
当最大值小于等于栈顶元素输出 然后出栈
#include<iostream>
#include<stdio.h>
#include<string>
#include<cstring>
#include<string.h>
#include<algorithm>
#include<map>
#include<vector>
#include<stack>
#include<queue>
#define MAXN 1000002
using namespace std;
int a[MAXN];//标记数组
stack <int> zhan;
vector <int> rongqi;
int main()
{
int n;
cin>>n;
int t=n;//n中途被改变了
int i,j,k=0;
for(i=0;i<n;i++)
{
int temp;
cin>>temp;
zhan.push(temp);
//cout<<zhan.top()<<endl;
a[temp]=1;
while(t&&a[t])
{
t--;
}
while(!zhan.empty()&&t<=zhan.top())
{
rongqi.push_back(zhan.top());
//cout<<zhan.top();
zhan.pop();
}
}
int tr=rongqi.size();
for(i=0;i<tr;i++)
{
if(k)
cout<<" ";
cout<<rongqi[i];
k=1;
}
/*
while(!rongqi.empty())
{
if(k)
cout<<" ";
cout<<rongqi.back();
k=1;
rongqi.pop_back();
}
*/
return 0;
}
然后就是最靠直觉的博弈论了,虽然很久前看过了那几种博弈
但是今天这道题目还是出乎我意料
不是那几种基本模型
而且可以说很简单,又可以说不简单??
如果把前10中情况写出来是挺离谱的先手奇数赢,偶数输
#include<iostream>
#include<algorithm>
#include<cstdio>
using namespace std;
int main()
{
int m,n;
while((scanf("%d %d",&m,&n))!=EOF)
{
if((m+n&1)==0)
cout<<"lose"<<endl;
else
cout<<"win"<<endl;
}
}
新类型题,目前感觉这种题能不能写出来全靠直觉,标答是写的SG函数,居然是一个模板题
高数
预习了前两节的内容
向量的方向角 方向余弦 向径矢量投影(prj) 数量积和向量积
附带习题
unique
作用 : 求数组元素个数
条件:有序
格式:
sort(a,a+n);
int t=unique(a,a+n)-a;
返回值:(跌带器)去重序列最后一个重复元素的后一个元素?? 我的理解和这有点冲突
我一开始以为返回值是元素个数??
这个说说实话很像桶排序,单是如果统计数据个数,用这个比桶排再遍历一遍桶理论上会快一点
明天学习学习动归、SG 和bfs 复习dfs