V——小M的移动硬盘 W——Languages X——数字和 Y——赏赐 OR 灾难 Z——图书管理员的表白方式

Description

最近小M买了一个移动硬盘来储存自己电脑里不常用的文件。但是他把这些文件一股脑丢进移动硬盘后,觉得这些文件似乎没有被很好地归类,这样以后找起来岂不是会非常麻烦?
小M最终决定要把这些文件好好归类,把同一类地移动到一起。所以现在小M有了这几种操作:
1 u 表示把编号为u的文件放到最上面
2 u 表示把编号为u的文件放到最下面
3 u v 表示把编号为u的文件放到编号为v的文件的后面
已知在最开始的时候,1号文件到n号文件从上往下排布
现在小M已经给出了他所进行的所有操作,你能告诉他操作之后的序列是会变成什么样子吗?

Input

第一行为一个数字T(T<=10)表示数据组数
第二行为两个数字n、m(1<=n,m<=300000)表示序列长度和小M的操作次数
接下来m行每行两个或三个数字,具体含义见题面
保证数据合法

Output

输出一行表示小M操作结束后的序列

Sample Input

1
10 5
1 5
2 3
2 6
3 4 8
3 1 3

Sample Output

5 2 7 8 4 9 10 3 1 6


#include <iostream>
#include <cstdio>
#include <string>
#include <string.h>
#include <queue>
#include <vector>
#include <stack>
#include <set>
#include <algorithm>
using namespace std;
#define ll long long
const int maxn = 300005;

int n;
int m;
int leftt[maxn];
int rightt[maxn];
int flag;
int a, b;

void init()
{
	rightt[0] = 1;
	leftt[n + 1] = n;
	for (int i = 1; i <= n; i++)
	{
		leftt[i] = i - 1;
		rightt[i] = i + 1;
	}
}

void link(int l, int r)
{
	rightt[l] = r;
	leftt[r] = l;
}

int main()
{

	int T;
	cin >> T;
	while (T--)
	{
		cin >> n >> m;
		init();
		for (int i = 0; i < m; i++)
		{
			cin >> flag;
			if (flag == 1)
			{
				cin >> a;
				if(rightt[0]==a)
                    continue;
				int la = leftt[a];
				int ra = rightt[a];
				int r0 = rightt[0];
				link(la, ra);
				link(a, r0);
				link(0, a);
			}
			else if (flag == 2)
			{
				cin >> b;
				if(leftt[n+1]==b)
                    continue;
				int lb = leftt[b];
				int rb = rightt[b];
				int ln = leftt[n + 1];
				link(lb, rb);
				link(ln, b);
				link(b, n + 1);
			}
			else
			{
				cin >> a >> b;
				if(rightt[b]==a)
                    continue;
				int la = leftt[a];
				int ra = rightt[a];
				int rb = rightt[b];
				link(la, ra);
				link(a, rb);
				link(b, a);
			}
		}
		int temp = rightt[0];
		cout << temp;
		while (rightt[temp] != (n + 1))
		{
			cout << " "<< rightt[temp] ;
			temp = rightt[temp];
		}
		cout<<endl;
	}
	return 0;
}

/**********************************************************************
	Problem: 1982
	User: jk1601zr
	Language: C++
	Result: WA
**********************************************************************/



/**********************************************************************
	Problem: 1982
	User: jk1601zr
	Language: C++
	Result: AC
	Time:956 ms
	Memory:4368 kb
**********************************************************************/

Description

The Enterprise has encountered a planet that at one point had been inhabited. The only remnant from the prior civilization is a set of texts that was found. Using a small set of keywords found in various different languages, the Enterprise team is trying to determine what type of beings inhabited the planet.

Input

The first line of input will be N (1 ≤ N ≤ 100), the number of different known languages. The next N lines contain, in order, the name of the language, followed by one or more words in that language, separated with spaces. Following that will be a blank line. After that will be a series of lines, each in one language, for which you are to determine the appropriate language. Words consist of uninterrupted strings of upper or lowercase ASCII letters, apostrophes, or hyphens, as do the names of languages. No words will appear in more than one language. No line will be longer than 256 characters. There will be at most 1000 lines of sample text. Every sample text will contain at least one keyword from one of the languages. No sample text will contain keywords from multiple languages. The sample text may contain additional punctuation (commas, periods, exclamation points, semicolons, question marks, and parentheses) and spaces, all of which serve as delimiters separating keywords. Sample text may contain words that are not keywords for any specific language. Keywords should be matched in a case-insensitive manner.

Output

For each line of sample text that follows the blank line separating the defined languages, print a single line that identifies the language with which the sample text is associated.

Sample Input

4
Vulcan throks kilko-srashiv k'etwel
Romulan Tehca uckwazta Uhn Neemasta
Menk e'satta prah ra'sata
Russian sluchilos

Dif-tor heh, Spohkh. I'tah trai k'etwel
Uhn kan'aganna! Tehca zuhn ruga'noktan!

Sample Output

Vulcan
Romulan

#include <iostream>
#include <cstdio>
#include <string.h>
#include <string>
#include <map>
#include <sstream>
using namespace std;

map<string,string>ma;
string lan,s;
char c;
string line,temp;

void change(string &str)
{
    int len=str.length();
    for(int i=0;i<len;i++)
        str[i]=tolower(str[i]);
}

int main()
{
    int T;
    cin>>T;
    while(T--)
    {
        cin>>lan;
        c=getchar();
        while(c!='\n')
        {
            cin>>s;
            change(s);
            ma[s]=lan;
            c=getchar();
        }
    }
    int flag=0;
    while(getline(cin,line))
    {
        for(int i=0;i<line.length();i++)
        {
            if(line[i]==','||line[i]==';'||line[i]=='.'||line[i]=='('||line[i]==')'||line[i]=='!'||line[i]=='?')
                line[i]=' ';
            stringstream ss(line);
            while(ss>>temp)
            {
                change(temp);
                if(flag==0)
                {
                    if(ma.count(temp))
                    {
                        cout<<ma[temp]<<endl;
                        flag=1;
                    }
                }
            }
        }
            if(c=='\n')
                flag=0;
    }
    return 0;
}

/**********************************************************************
	Problem: 1826
	User: jk1601zr
	Language: C++
	Result: AC
	Time:756 ms
	Memory:2348 kb
**********************************************************************/


Description

长者对小明施加了膜法,使得小明每天起床就像马丁的早晨一样。 今天小明早上起来后发现身体虽然变小,头脑依旧不变变傻。

他有一条纸带,上面有n个数字,第i个数字为Ai。 他想把纸带选三个位置p1, p2, p3(p1 < p2 < p3)把纸带剪成4个每条长度至少为1的4条纸带。 分别为[1, p1-1], [p1+1, p2-1], [p2+1, p3-1], [p3+1, n],使得4个部分中数字之和相等。

扫描二维码关注公众号,回复: 1450060 查看本文章

Input

多组输入 每组测试数据第一行输入一个n(7 ≤ n ≤ 105) 第二行n个数,第i个数为Ai(0 ≤ Ai ≤ 109),表示第i个数

Output

输出字典序最小的p1,p2,p3 如果不存在这种操作,输出-1

Sample Input

7
6 2 6 2 6 2 6
7
1 2 3 4 5 6 7

Sample Output

2 4 6
-1


#include <iostream>
#include <cstdio>
#include <string.h>
#include <string>
#include <map>
#include <sstream>
using namespace std;
const int maxn = 1e5+10;
  
int a[maxn];  
int sum[maxn];  
int p1,p2,p3;  
int n;  

int slove()  
{  
    p1 = 2;  
    p2 = 4;  
    p3 = 6;  
    for(;p1<=n;p1++)  
    {  
        p2 = max(p2,p1+2);  
        while(p2<=n&&sum[p1-1]>sum[p2-1]-sum[p1]) p2++;  
        if(p2>=n||sum[p1-1]<sum[p2-1]-sum[p1])  
            continue;  
        p3 = max(p3,p2+2);  
        while(p3<=n&&sum[p1-1]>sum[p3-1]-sum[p2]) p3++;  
        if(p3>=n||sum[p3-1]-sum[p2]>sum[p1-1])  
            continue;  
        if(sum[n]-sum[p3]==sum[p1-1])  
        {  
            cout<<p1<<' '<<p2<<' '<<p3<<endl;  
            return 1;  
        }  
    }  
    return 0;  
} 
 
int main()  
{  
    while(cin>>n)  
    {  
        for(int i = 1 ;i<=n;i++)  
        {  
            cin>>a[i];  
            sum[i] = sum[i-1] + a[i];  
        }  
        if(!slove())  
        {  
            cout<<"-1"<<endl;  
        }  
    }  
}  

/**********************************************************************
	Problem: 1956
	User: jk1601zr
	Language: C++
	Result: AC
	Time:764 ms
	Memory:2804 kb
**********************************************************************/


Description

大G南征北战终于打下了大片土地成立了G国,大G在开国大典上传召帮助自己南征北战的三大开国元勋小A,小B,小C进殿,并要赏赐三人大量宝物以显示天恩浩荡。大G在征服其他国家的时候抢夺了n箱宝物,他把这些箱子依次排列在三人面前,每个箱子里的宝物都有一个价值wi,大G令他们一人选取一个箱子作为奖励。 可是令大G万万没有想到的是,三人在私底下是存在竞争关系的,由于小B手上兵权强于小C,小C手上兵权强于小A。所以弱者总是担心自己领取的赏赐高于或等于强者会招来杀身之祸。所以他们三人总是会让小B先选取奖励之后,小C会在小B选择的右侧区域选择价值比小B小的奖励,而小A则会在小B选择的左侧区域选择价值比小B和小C都小的奖励。当然小B是个聪明人,他也会考虑到两人的想法选择对大家都有帮助的方案选取。请问是否存在这样一种选择方案让大家都不用担心会招致杀身之祸。如果存在输出“YES”,否则输出“NO”

Input

多组数据读入
每组数据第一行输入一个正整数n表示n箱宝物(n<=100000) 接下来一行输入n个正整数w1,w2,w3,...,wn表示n箱宝物的价值。(wi<=10000000) 题目保证所有数据n的总和不超过500000

Output

如果存要求的选择方案则输出“YES”,否则输出“NO”。

Sample Input

6
1 2 3 6 5 4
6
1 2 3 4 5 6

Sample Output

YES
NO

#include<iostream>
#include<string>
#include<cstdio>
#include<stack>
#include<algorithm>
using namespace std;
const int MAXN=100005;
const int INF=1000000000;
int Min[MAXN];
int w[MAXN];
stack<int> s;

int main()
{
    int n;
    while(cin>>n)
    {
        while(!s.empty()) s.pop();
        for(int i=1;i<=n;i++)
        {
            cin>>w[i];
            if(i==1) Min[i]=w[i];
            else Min[i]=min(Min[i-1],w[i]);
        }
        bool flag=false;
        s.push(w[n]);
        for(int i=n-1;i>=2;i--)
        {
            int a=Min[i-1];
            int c=-1;
            while(!s.empty()&&s.top()<w[i])
            {
                c=s.top();
                s.pop();
            }
            s.push(w[i]);
            if(c>a)
            {
                flag=true;
                break;
            }
        }
        if(flag) cout<<"YES"<<endl;
        else cout<<"NO"<<endl;
    }
    return 0;
}
/**********************************************************************
	Problem: 1901
	User: jk1601zr
	Language: C++
	Result: AC
	Time:528 ms
	Memory:3196 kb
**********************************************************************/


Description

小V是中南大学图书馆的图书管理员,每天要整理很多同学们还回来的书。久而久之,他认识了很多常来图书馆的同学,比如说小L。简而言之吧,就是小V喜欢上了小L,并且想在下一次她来还书的时候表白。
小V的创意还是不错的,他精心准备了各种材料,打算构成“L”,“O”,“V”,“E”四个字母,在小L来的时候悄悄组合起来给她看。但是意外来了:在小L来的时候,小V只准备好了“L”,“O”,和“E”,“V”还没有拼好!但是机智的小V立刻想到了一个办法:他可以随手把旁边别人还的书合在一起,并且抽掉其中一部分,令剩下的书的高度构成了一个“V”形。
那么问题来了:已知N本书的高度,在不改变他们的顺序的前提下,能不能得到小V想要的“V”,如果可以的话,最少去掉多少本书呢?
(组成“V”的前提:h1>h2...<hn,即整个高度必须先递减再递增)

Input


多组数据,第一行有一个整数T,表示有T组数据。(T<=100
以下每组数据第一行有一个整数N,表示这一排书的数量。(1<=N<=100)

然后接下来一行是N个整数,h1,h2...hn分别代表每本书的高度。(1<=hi<=100)

Output

如果可以构成”V”,输出“HAPPY”,并在下一行输出所需拿掉的最少数量。
如果不能,输出“SAD”。

Sample Input

7
3
3 2 3
4
3 2 4 3
5
1 2 4 6 7
1
22
2
25 8
3
98 16 68
4
88 14 82 69

Sample Output

HAPPY
0
HAPPY
1
SAD
SAD
SAD
HAPPY
0
HAPPY
1

#include<iostream>  
#include<cstring>  
using namespace std;  
int dp1[105],dp2[105];  
int ax[105];  
int main()  
{  
    int T;  
    cin>>T;  
    while(T--)  
    {  
        int N,flag1=0,flag2=0,cnt=100000;  
        cin>>N;  
        for(int i=0;i<N;i++)  
        {  
            cin>>ax[i];  
            dp1[i]=dp2[i]=1;  
        }  
        for(int j=1;j<N-1;j++)  
        {  
             for(int i=0;i<N;i++)  
              dp1[i]=dp2[i]=1;  
  
            int cnt1=0,cnt2=0;  
            for(int i=j;i>=0;i--) 
            {  
                for(int k=i-1;k>=0;k--)  
                {  
                    if(ax[i]<ax[k])  
                   {  
                    flag1=1;  
                    dp1[k]=max(dp1[k],dp1[i]+1);  
                   }  
                   cnt1=max(dp1[k],cnt1);  
            }  
            }  
            for(int k=j;k<=N-1;k++) 
            {  
                for(int i=k+1;i<=N-1;i++)  
                {  
                    if(ax[k]<ax[i])  
                  {  
                    flag2=1;  
                    dp2[i]=max(dp2[i],dp2[k]+1);  
                  }  
                    cnt2=max(dp2[i],cnt2);  
                }  
  
            }  
            cnt=min(N-(cnt1+cnt2-1),cnt);  
        }  
        if(flag1&&flag2)  
          {  
              cout<<"HAPPY"<<endl;  
              cout<<cnt<<endl;  
          }  
        else  
            cout<<"SAD"<<endl;  
  
    }  
    return 0;  
}  
/**********************************************************************
	Problem: 1560
	User: jk1601zr
	Language: C++
	Result: AC
	Time:56 ms
	Memory:2024 kb
**********************************************************************/


猜你喜欢

转载自blog.csdn.net/abandoninged/article/details/80259602
今日推荐