您的位置:首页 > 其它

【链表】URAL 1579 Coat Transportation

2015-02-01 20:13 399 查看
点击打开链接

题意:一个不递减的序列,一次能选取相差大于R的数列,要求最少次数选完所以的数。

并输出。

#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <string>
#include <iostream>
#include <algorithm>
#include <sstream>
#include <cmath>
using namespace std;
#include <queue>
#include <stack>
#include <set>
#include <vector>
#include <deque>
#include <map>
#define cler(arr, val) memset(arr, val, sizeof(arr))
typedef long long LL;
const int MAXN = 120000;
const int MAXM = 140000;
const int INF = 0x3f3f3f3f;
const int mod = 1000000007;
#define lson l,m,rt<<1
#define rson m+1n 0;,r,rt<<1|1
int head[MAXN],q[MAXN];
struct node
{
int next,a;
}edge[MAXN];
int main()
{
int n,r,top=0;
cler(edge,-1);
cin>>n>>r>>edge[0].a;
edge[0].next=-1;
for(int i=1;i<n;i++)
{
cin>>edge[i].a;
if(edge[i].a>edge[top].a+r)
{
edge[i].next=top;
top++;
}
}
printf("%d\n",n-top);
for(int i=top;i<n;i++)
{
int k=0;
for(int j=i;~j;j=edge[j].next)
{
q[k++]=j+1;
}
cout<<k;
for(int j=k-1;j>=0;j--)
printf(" %d",q[j]);
printf("\n");
}
return 0;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: