【链表】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;
}
题意:一个不递减的序列,一次能选取相差大于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;
}
相关文章推荐
- URAL 1992 CVS 链表
- CVS (URAL 1992 可持久化的链表)
- URAL 1992 CVS 链表
- URAL 1434 Buses in Vasyuki (双静态邻接链表+BFS)
- 用迭代器构建的单链表
- Linux kernel 中的链表list 使用示例
- 用二级指针操作不带头结点的单链表
- 单向链表的一些操作
- 合并两个排序的链表
- 单向链表特点实现
- 从尾到头输出链表
- 数据结构c语言实现-链表(带和不带头节点)
- 数组与链表的优缺点
- [剑指offer]两个链表的第一个公共结点
- 一个统一的链表结构
- 算法导论笔记之----双向链表
- 1511 从尾到头打印链表
- 约瑟夫问题的单向循环链表的解法
- 剑指offer-第三章高质量的代码(输出该链表中倒数第K个节点)
- 2.2链表中倒数第k个结点