• 2019-2020 ICPC Southwestern European Regional Programming Contest(SWERC 2019) (F,G,K)



    10.4 2019-2020 ICPC Southwestern European Regional Programming Contest(SWERC 2019)

    CF

    当时十分划水 也没什么要补的题..(怕不是要成水题集


    F.Icebergs√

    //计算几何模板,求多边形面积。
    #include <bits/stdc++.h>
    #define gc() getchar()
    typedef long long LL;
    const int N=1005;
    const double eps=1e-10;
    
    inline int dcmp(double x) {return fabs(x)<eps?0:x<0?-1:1;}
    
    struct Vec
    {
    	LL x,y;
    	Vec(LL x=0,LL y=0):x(x),y(y) {}
    	Vec operator +(const Vec &a)const {return Vec(x+a.x,y+a.y);}
    	Vec operator -(const Vec &a)const {return Vec(x-a.x,y-a.y);}
    	Vec operator *(const double a)const {return Vec(x*a,y*a);}
    
    	LL operator *(const Vec &a)const {return x*a.y-y*a.x;}
    	bool operator <(const Vec &a)const {return x<a.x||(x==a.x&&y<a.y);}
    	bool operator ==(const Vec &a)const {return !dcmp(x-a.x)&&!dcmp(y-a.y);}
    };
    typedef  Vec Point;
    struct Polygon
    {
    	std::vector<Point> ps;
    	LL Area()//多边形有向面积(逆时针为正,顺时针为负) 
    	{
    		LL res=0;
    		for(int i=1,lim=ps.size(); i+1<lim; ++i)
    			res+=(ps[i]-ps[0])*(ps[i+1]-ps[0]);
    		return abs(res);
    	}
    }poly;
    
    bool cmp(Point a,Point b)
    {
    	if(atan2(a.y,a.x)!=atan2(b.y,b.x))
    		return atan2(a.y,a.x)<atan2(b.y,b.x);
    	else return a.x<b.x;
    }
    
    inline int read()
    {
    	int now=0,f=1; char c=gc();
    	for(; !isdigit(c); c=='-'&&(f=-1),c=gc());
    	for(; isdigit(c); now=now*10+c-48,c=gc());
    	return now*f;
    }
    
    int main()
    {
    	LL res=0;
    	for(int Ts=read(); Ts--; )
    	{
    		int n=read();
    		poly.ps.clear();
    		for(int i=1,x; i<=n; ++i) x=read(),poly.ps.push_back(Point(x,read()));
    		res+=poly.Area();
    	}
    	printf("%lld
    ",(res/2));
    
    	return 0;
    }
    

    G.Swapping Places(拓扑排序)

    如果(i,j(i<j))两个位置不是朋友,那么(j)永远不可能到(i)前面,否则(i)(j)没有限制。
    所以可以考虑拓扑排序。。如果两个位置(i,j(i<j))处不是朋友,则连边(i->j),即选完(i)后才能选(j)
    字典序最小的拓扑就是把queue换成priority_queue

    //467ms	65800KB
    #include <bits/stdc++.h>
    #define gc() getchar()
    typedef long long LL;
    const int N=1e5+5;
    
    int A[N],las[N],dgr[N];
    bool fri[205][205];
    std::string str[222];
    std::vector<int> to[N];
    std::unordered_map<std::string,int> mps;
    
    struct cmp
    {
    	bool operator ()(int a,int b)
    	{
    		return A[a]>A[b];
    	}
    };
    std::priority_queue<int,std::vector<int>,cmp> q;
    
    inline int read()
    {
    	int now=0,f=1; char c=gc();
    	for(; !isdigit(c); c=='-'&&(f=-1),c=gc());
    	for(; isdigit(c); now=now*10+c-48,c=gc());
    	return now*f;
    }
    
    int main()
    {	
    	int S=read(),l=read(),n=read();
    	for (int i=1; i<=S; ++i) std::cin>>str[i];
    	std::sort(str+1,str+S+1);
    	for (int i=1; i<=S; ++i) mps[str[i]]=i;
    
    	std::string s1,s2;
    	for(int i=1,x,y; i<=l; ++i) 
    		std::cin>>s1>>s2, x=mps[s1], y=mps[s2], fri[x][y]=1, fri[y][x]=1;
    	for(int i=1; i<=n; ++i) std::cin>>s1, A[i]=mps[s1];
    
    	for(int i=1; i<=n; ++i)
    	{
    		for(int j=1,x=A[i]; j<=S; ++j)
    			if(las[j] && !fri[x][j])
    				to[las[j]].push_back(i), ++dgr[i];
    		las[A[i]]=i;
    	}
    
    	for(int i=1; i<=n; ++i) if(!dgr[i]) q.push(i);
    	while(!q.empty())
    	{
    		int x=q.top(); q.pop();
    		std::cout<<str[A[x]]<<' ';
    		for(auto j:to[x])
    			if(!--dgr[j]) q.push(j);
    	}
    
    	return 0;
    }
    

    K.Birdwatching(BFS)√

    记与起点相邻的点的集合为S。建反向图BFS。如果有一个点能从S中的两个点到达,则不行。

    #include <bits/stdc++.h>
    #define pr pair<int,int>
    #define mp make_pair
    #define pb push_back
    #define fir first
    #define sec second
    using namespace std;
    const int N = 1e5+10;
    
    vector<int> e[N],vec;
    int is[N], vis[N], tmp[N];
    bool ban[N];
    queue<pr> q;
    
    int main()
    {
    	int n, m, t; cin>>n>>m>>t;
    	for(int i=0; i<m; i++)
    	{
    		int u, v; scanf("%d%d",&u,&v);
    		e[v].pb(u);
    	}
    	memset(is, 0, sizeof(is));
    	memset(vis, 0, sizeof(vis));
    	for(auto &y: e[t]) q.push(mp(y,y)), is[y] = 1;
    
    	vis[t] = N;
    	while(!q.empty())
    	{
    		int x=q.front().first,pre=q.front().second; q.pop();
    		if(x!=pre) ban[x]=1;//, printf("ban x:%d pre:%d
    ",x,pre);
    		for(auto &v:e[x])
    		{
    			if(vis[v]>=2||v==pre) continue;
    			if(vis[v]==1 && tmp[v]==pre) continue;
    			else if(!vis[v]) tmp[v]=pre;
    			++vis[v], q.push(mp(v,pre));
    		}
    	}
    	for(int i=0; i<n; i++)
    		if(is[i] && !ban[i]) vec.pb(i);
    	cout<<vec.size()<<endl;
    	for(auto &x: vec) printf("%d
    ",x);
    
    	return 0;
    }/*
    4 4 4
    1 2 2 3 3 1 3 4
    5 7 0
    1 2 2 3 3 1 3 0 4 0 3 4 4 2
    8 11 0
    1 4 1 2 4 2 2 3 3 1 3 0 2 5 5 0 5 6 6 7 7 2
    12 15 0
    1 4 1 2 4 2 2 3 3 1 3 0
    7 2 6 7 5 6 5 0
    2 8 8 9 9 10 10 11 11 5
    */
    
  • 相关阅读:
    怎样用wordpress建立一个博客
    TCP三次握手
    抓取动态页面
    Controller的激活
    使用PHPnow搭建本地wordpress
    自己动手从头制作WordPress主题探索add_action和do_action
    Cat in dotNET
    如何在本地搭建Wordpress环境
    Windows7下Emacs的安装
    Windows下Emacs的安装
  • 原文地址:https://www.cnblogs.com/SovietPower/p/13854418.html
Copyright © 2020-2023  润新知