美文网首页
2018-03-10 STL

2018-03-10 STL

作者: _弓长_大人 | 来源:发表于2018-09-25 12:42 被阅读5次

优先队列
结构体优先队列

// 这里是小的优先,默认是大的优先
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
ll t,n;
priority_queue<int,vector<int>,greater<int> >q;
int  main(){

q.push(3);
q.push(2);
int x=q.top();
cout<<x<<endl;
return 0;
}


// 对结构题进行优先队列 需要重载运算符
#include<cstdio>
#include<queue>
using namespace std;
struct node
{
    int x,y;
    bool operator < (const node & a) const
    {
        return x<a.x;
    }
}k;
priority_queue <node> q;
int main()
{
    k.x=10,k.y=100; q.push(k);
    k.x=12,k.y=60; q.push(k);
    k.x=14,k.y=40; q.push(k);
    k.x=6,k.y=80; q.push(k);
    k.x=8,k.y=20; q.push(k);
    while(!q.empty())
    {
        node m=q.top(); q.pop();
        printf("(%d,%d) ",m.x,m.y);
    }
}

set

// [天梯](https://www.patest.cn/contests/gplt/L2-014)
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;

int  main(){
int n;
set<int>s;
cin>>n;
int t;
s.insert(0);
for(int i=0;i<n;i++){
    cin>>t;
    if(*s.rbegin()>t){
        s.erase(s.upper_bound(t));
    }
    s.insert(t);
}
cout<<s.size()-1<<endl;
return 0;
}

map

//  定义的三元组 用 map 判读是否 重复出现
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define N 25004
int k;
ll aa[N];

int c=0;


ll  gcd(ll a,ll b)
{
    return b==0?a:gcd(b,a%b);
}

    class Key
    {
    public:
        Key();
        Key(ll a,ll b,ll c);
        ll x,y,z;
        ~Key();

        bool operator <(const Key& key) const;
    };
    bool Key::operator <(const Key &key)  const
    {        if(this->x<key.x||this->x==key.x&&this->y<key.y||this->x==key.x&&this->y==key.y&&this->z<key.z)
            return true;
        else
            return false;
    }
    Key::Key()
    {
    }
    Key::Key(ll a,ll b,ll c)
    {
        x=a;y=b;z=c;
    }
    Key::~Key()
    {
    }
    map<Key,int>ma;
int main()
{
    cin>>k;
    ll x,y,z;
    cin>>x>>y>>z;
    ll a,c,b;

       for(int i=1;i<k;i++)
       {
          cin>>a>>b>>c;
          a=a-x;
          b-=y;c-=z;
          if(a!=0&&b!=0&&c!=0)
          {
         ll tem=gcd(a,b);
         tem=gcd(tem,c);
         a/=tem;b/=tem;c/=tem;
          }
         Key node;
         node.x=a;node.y=b;node.z=c;
       //  cout<<"dsaf "<<node.x<<" "<<node.y<<" "<<node.z<<endl;
         ma[node]=1;
          Key node2;
         node2.x=-a;node2.y=-b;node2.z=-c;
       //   cout<<node2.x<<" "<<node2.y<<" "<<node2.z<<endl;
         ma[node2]=1;
       }
     //  cout<<ma.size()<<endl;
      cout<<(ma.size()+1)/2<<endl;



    return 0;
}

相关文章

  • 2018-03-10 STL

    优先队列结构体优先队列 set map

  • 放了自己

    2018-03-10 姣颜 2018-03-10 23:35 · 字数 295 · 阅读 0 · 日记本 前几天因...

  • stl简介

    stl stl简介 1. 什么是STL? STL(Standard Template Library),封装基本数...

  • C++标准库结构与使用

    本文预览: 标准库和STL STL的六大组件 STL容器分类 STL容器使用 标准库和STL ** 我们在写C++...

  • GeekBand笔记: STL与泛型编程(容器)

    stl stl 6 componentsallocatorcontaineralgorithmiteratorfu...

  • Boolan - C++学习笔记 _STL - 第一周

    STL与泛型编程 一、STL是什么 STL(Standard TemplateLibrary),即标准模板...

  • C++ STL

    STL STL 是“Standard Template Library”的缩写,中文译为“标准模板库”。STL 是...

  • C++基础一文通(六)STL

    一. STL 标准模板库 STL(Standard Template Library,标准模板库) STL 从广义...

  • C++ STL是什么

    STL 组件主要包括容器,迭代器、算法和仿函数。STL 基本结构和 STL 组件对应。 STL 主要由迭代器、算法...

  • C++ STL编程

    一、STL简介 1.1 初识STL STL(Standard Template Library,即标准模版库)是一...

网友评论

      本文标题:2018-03-10 STL

      本文链接:https://www.haomeiwen.com/subject/aupvfftx.html