Time Limit Exceed 小球移动Description有一排小球,自左至右依次编号为1,2,3,...,n,可执行两种指令移动小球,L X Y表示将小球X移到小球Y的左边,R X Y表示将小球X移到小球Y的右边,保证X!=Y.输入小球的个数

来源:学生作业帮助网 编辑:六六作业网 时间:2024/12/20 01:03:40
TimeLimitExceed小球移动Description有一排小球,自左至右依次编号为1,2,3,...,n,可执行两种指令移动小球,LXY表示将小球X移到小球Y的左边,RXY表示将小球X移到小球

Time Limit Exceed 小球移动Description有一排小球,自左至右依次编号为1,2,3,...,n,可执行两种指令移动小球,L X Y表示将小球X移到小球Y的左边,R X Y表示将小球X移到小球Y的右边,保证X!=Y.输入小球的个数
Time Limit Exceed 小球移动
Description
有一排小球,自左至右依次编号为1,2,3,...,n,可执行两种指令移动小球,L X Y表示将小球X移到小球Y的左边,R X Y表示将小球X移到小球Y的右边,保证X!=Y.输入小球的个数n,指令的条数m和对应的m条指令,请输出最后小球的顺序(提示:n可能高达500000,m可能高达1000000).
Input
小球个数和指令的条数,对应的具体指令
有多组数据
Output
最后小球的顺序
Sample Input
6 2
L 1 4
R 3 5
Sample Output
2 1 4 5 3 6
#include
#include
#define MAXBALL 500000
#define MAXCOM 100000
typedef struct ball
{
int num;
struct ball *next;
} Ball;
Ball* create(int n)
{
int i;
Ball *head,*p,*q;
head = (Ball*) malloc (sizeof(Ball));
head->num = 0;
head->next = NULL;
q = head;
for (i = 0; i < n; i++){
p = (Ball*) malloc (sizeof(Ball));
p->num = i+1;
q->next = p;
q = p;}
q->next = NULL;
return head;
}
Ball* move(Ball* head,int m)
{
int i,x,y;
char com;
Ball *px,*prex,*py,*prey;
for (i=0; i < m; i++)
{
prex = prey = head;
px = prex->next;
py = prey->next;
scanf ("\n%c%d%d",&com,&x,&y);
if (x == y){
exit (1);
}
else
{
while (px->num = x)
{
prex = px;
px = prex->next;
}
while (py->num = y)
{
prey = py;
py = prey->next;
}
if (com == 'L')
{
prex->next = px->next;
prey->next = px;
px->next = py;
}
else if (com == 'R')
{
prex->next = px->next;
px->next = py->next;
py->next = px;
}
}
}
return head;
}
void destroy(Ball* head,int n)
{
int i;
Ball *p;
for (i = 1; i < n ; i++)
{
p = head;
head = head->next;
free (p);
}
free(head);
}
void show(Ball* head)
{
Ball *p;
p = head->next;
while (p)
{
printf ("%d ",p->num);
p = p->next;
}
printf ("\n");
}
int main()
{
int x,y;
char com;
int n,m;
while(scanf ("%d%d",&n,&m) = EOF){
if (n > MAXBALL || m > MAXCOM)
exit (1);
Ball* head = create(n);
move(head,m);
show(head);
destroy(head,n);
}
return 0;
}
为什么Time Limit Exceed 怎么修改呢

Time Limit Exceed 小球移动Description有一排小球,自左至右依次编号为1,2,3,...,n,可执行两种指令移动小球,L X Y表示将小球X移到小球Y的左边,R X Y表示将小球X移到小球Y的右边,保证X!=Y.输入小球的个数
#include
const int MAX=500005;
struct NODE
{
int l,r;
}node[MAX];
int main()
{
//用链用做,你的每次查找复杂度是O(n)我的是O(1)
int n,m,i,j,l,r;
char cmd[10];
while(scanf("%d%d",&n,&m)!=EOF)
{
for(i=1;i

you absolutely must not exceed the time limit Time Limit Exceed 小球移动Description有一排小球,自左至右依次编号为1,2,3,...,n,可执行两种指令移动小球,L X Y表示将小球X移到小球Y的左边,R X Y表示将小球X移到小球Y的右边,保证X!=Y.输入小球的个数 sender daily send mail exceed limitoutlook 2007 提示: sender daily send mail exceed limit TIME LIMIT怎么样 don't exceed speed limit 这里的limit怎么理解 什么词性 一道ACM题,总是 output limit exceed,谁能告我为什么是这个错误1013:The 3n + 1 problem Time Limit:1 Sec Memory Limit:64 MBSubmit:58 Solved:16[Submit][STATUS][Web Board]DescriptionConsider the following algorithm to generate a sequence of 翻译If you exceed the speed limit,you will get into trouble with the police谢谢 request is inwalid you've exceed the rate limit 是啥意思 C语言OJ题错误代码Output Limit Exceed,Description计算a+b,0 You will be given a ticket if you __________ the speed limit.proceed exceed succeed precede 为什么会是time limit exceed#include #include using namespace std;int main(){int i,j,q,p,w,r;char a[100000];char b[100000];while(cin>>a>>b){w=0;r=0;for(i=0;i 用PAYPAL时出现了EXCEED SENDING The amount of this transaction exceeds your sending limit and cannot be processed at this time.You will need to add and confirm your bank account.Once your bank account has been added and confirmed,you can continue acm 为什么老是time limit exceed现在先给你一个简单的问题:n个整数a(1),a(2),a(3)…a(n); 每个询问给你两个数:i,j 要求你算出a(i) + a(i+1)…+a(j)的和.Input第一行一个整数 T,代表T组数据.每组数据第一 c语言Time Limit Exceed 该怎么修改啊DescriptionYou still are worried about reading acm English problem, let me tell you a kind of very good method of Memorising Words, the root memory method,.the most interesting of the method is the prefix ro C语言OJ 提交提示 “Time Limit Exceed”Description 我们知道人民币有1、2、5、10、20、50、100这几种面值.现在给你n(1≤n≤250)元,让你计算换成用上面这些面额表示且总数不超过100张,共有几种.比如4 一个很简单的ACM题,这个提交后怎么会“Time Limit Exceed”?Description 给你一个整数m(1《m《1000000),你能快速算出m的因子个数是个数n吗?一个整数本身是自己的因子!Input 输入数据包含多个测试实 limit Limit