Welcome, Guest! Sign Up RSS

Clever Space

Friday, 11.22.2024
Main » 2013 » October » 23

终于想出来怎么处理环了

#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<set>
#include<algorithm>
#include<map>
#include<vector>
#include<queue>
#include<iostream>
#include<string>
#include<cmath>
#define N 300010
#define FOR(i,a,b) for(i=(a);i<=(b);i++)
#define ROF(i,a,b) for(i=(a);i>=(b);i--)
typedef long long LL;
using namespace std;
int nxt[N],len[N],vis[N],n,p,cnt;
void dfs(int x,int T)
{
  if (vis[x]==T) 
  {
    p=x,cnt=1;
    while (nxt[p]!=x) p=nxt[p],cnt++;
    p=x;len[p]=cnt;
    while (nxt[p]!=x)
    {
      p=nxt[p];
      le ... Read more »
Views: 345 | Added by: dhy0077 | Date: 10.23.2013

哈哈,原来水题一道

碰撞时交换速度,就不用考虑车之间的碰撞了,

只要考虑一下和挡板的碰撞就行了,

用堆维护碰撞时间。

std::priority_queue是个不错的选择.


#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<set>
#include<algorithm>
#include<map>
#include<vector>
#include<queue>
#include<iostream>
#include<string>
#include<cmath>
#define N 100010
#define FOR(i,a,b) for(i=(a);i<=(b);i++)
#define ROF(i,a,b) for(i=(a);i>=(b);i--)
typedef long long LL;
using namespace std;
int n,m,k;
struct node
{
  double t,v;int d;
  bool operator<(const node A)const
  {
    return t>A.t;
  }
};
int times[N];
priority_queue<node> h ... Read more »
Views: 457 | Added by: dhy0077 | Date: 10.23.2013