训练赛题解

B - Memory

Singing a song with cups of drink, That days are short is what I think. They are like dews in morning early, Therefore, I feel suffered for time gone surely.

Little G used to be a participant in programming contests and he had attended n𝑛 contests in total, and for the i𝑖-th contest, Little G got ai𝑎𝑖 happiness. However, Little G would also be influenced by past contests since memory also plays an important role to influence one's mood. So we can use following formula to value Little G's mood after the i𝑖-th contest:

Mood(i)=∑j=1i2j−i×aj

Now Little G is recalling the past and is curious about the moods after every contest, so he wants to tag the moods for every contest. Specifically, Little G will tag a positive sign ("+") for the i𝑖-th contest if Mood(i)>0, or tag a negative sign ("-") if Mood(i)<0, or tag a zero ("0") if Mood(i)=0. But Little G is busy working and working, so he is now asking you, the best programming contestant, to help him tag the moods.

Input

The first line contains one integers n𝑛 (1≤n≤1051≤𝑛≤105), denoting the number of contests Little G had attended.

The second line contains n𝑛 integers a1,a2,…,an𝑎(−10^9≤ai≤10^9), denoting the happiness values after every contest.

Output

Output one line containing a string which is of length n𝑛 and only contains "+", "-" or "0", denoting the mood tags after every contest.

Examples

InputcopyOutputcopy
10
2 -1 4 -7 4 -8 3 -6 4 -7
+0+-+---+-

Note

  • Mood(1)=20×2=2>0
  • Mood(2)=2−1×2+20×(−1)=0
  • Mood(3)=2−2×2+2−1×(−1)+20×4=4>0
  • Mood(4)=2−3×2+2−2×(−1)+2−1×4+20×(−7)=−5<0
  • Mood(5)=2−4×2+2−3×(−1)+2−2×4+2−1×(−7)+20×4=32>0

首先可以看出若为整数,则b+=b/2+a[i],若为浮点数,一直除以2会造成浮点数的损失,需要避免浮点数的损失,则用s=1.0*b/2.0-b/2;来判断,若s>0输出+,s<0输出-,s==0输出0.

#include<bits/stdc++.h>
using namespace std;
int a[1000010];
int main()
{
	int n;
	cin>>n;
	for(int i=0;i<n;i++)
	cin>>a[i];
	double s=0;
	int b=0;
	for(int i=0;i<n;i++)
	{
		b+=a[i];
		if(b%2!=0)
		s=1.0*b/2.0-b/2;
		if(b>0)
		cout<<"+";
		if(b<0)
		cout<<"-";
		if(b==0)
		{
			if(s==0)
			cout<<"0";
			if(s>0)
			cout<<"+";
			if(s<0)
			cout<<"-";
		}
		b/=2;
	}
	return 0;
}

M - Painter

Little G is a painter and is painting on a 2D plane. Each integral point has a color character and the initial color characters for all integral points are "."(ASCII = 46). Now Little G is planning to do some operations one by one, where each operation is in one of the following three types:

  1. "Circle xyrcol𝑥𝑦𝑟𝑐𝑜𝑙", which means to draw a circle. Formally, change the color characters to col𝑐𝑜𝑙 for these points (u,v)that (u−x)2+(v−y)2≤𝑟2.
  2. "Rectangle x1y1x2y2col", which means to draw a rectangle. Formally, change the color characters to col𝑐𝑜𝑙 for these points (u,v) that x1≤u≤x2,y1≤v≤y2.
  3. "Render x1y1x2y2", which means to render the image of given region. Formally, print the color characters for these points (u,v)(𝑢,𝑣) that x1≤u≤x2,y1≤v≤y2.

But now, Little G is busy replying clarifications, so could you help him and be the painter?

Input

The first line contains one integers n𝑛 (1≤n≤2000), denoting the number of operations.

Following n𝑛 lines each contains one operation, which is in one of the following three types:

  1. "Circle xyrcol(0≤|x|,|y|,r≤109)𝑥𝑦𝑟𝑐𝑜𝑙(0≤|𝑥|,|𝑦|,𝑟≤10^9)", which means to draw a circle. Formally, change the color characters to col𝑐𝑜𝑙 for these points (u,v) that (u−x)2+(v−y)2≤r2.
  2. "Rectangle x1y1x2y2col(−10^9≤x1≤x2≤10^9,−10^9≤y1≤y2≤10^9)", which means to draw a rectangle. Formally, change the color characters to col𝑐𝑜𝑙 for these points (u,v) that x1≤u≤x2,y1≤v≤y2.
  3. "Render x1y1x2y2(−10^9≤x1≤x2≤10^9,−10^9≤y1≤y2≤10^9)", which means to render the image of given region. Formally, print the color characters for these points (u,v) that x1≤u≤x2,y1≤v≤y2.

It is guaranteed that all of the x,y,r,x1,y1,x2,y2 above are integers.

It is guaranteed that the sum of the rendering region areas(which equal (x2−x1+1)×(y2−y1+1)( doesn't exceed 104, and that col𝑐𝑜𝑙 denotes visible characters, whose ASCII codes are between 33 and 126.

Output

For each rendering operation "Render x1y1x2y2", print y2−y1+1 lines each containing one string of length x2−x1+1, denoting the region image(from row y2 to row y1).

Examples

InputcopyOutputcopy
7
Circle 0 0 5 *
Circle -2 2 1 @
Circle 2 2 1 @
Rectangle 0 -1 0 0 ^
Rectangle -2 -2 2 -2 _
Render -5 -5 5 5
Render -1 0 1 2
.....*.....
..*******..
.**@***@**.
.*@@@*@@@*.
.**@***@**.
*****^*****
.****^****.
.**_____**.
.*********.
..*******..
.....*.....
@*@
***
*^*

#include<bits/stdc++.h>
#define int long long
#define IOS ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
using namespace std;
struct node
{
	int x,y,x1,x2,y1,y2,r,flag;
    char l;
}d[2100];

int check(int u,int v,int x,int y,int r)
{
	if((u-x)*(u-x)+(v-y)*(v-y)<=r*r)
	return 1;
	else 
	return 0;
}
int check1(int u,int v,int x1,int y1,int x2,int y2)
{
	if(u>=x1&&u<=x2&&v>=y1&&v<=y2)
	return 1;
	else
	return 0;
}
signed main()
{
	IOS
	int n;
	cin>>n;
	int m=0;
	for(int i=1;i<=n;i++)
	{
		string s;
		cin>>s;
		if(s=="Circle")
		{
			cin>>d[m].x>>d[m].y>>d[m].r;
			d[m].flag=1;
			cin>>d[m].l;
			m++;
		}
		else if(s=="Rectangle")
		{
			cin>>d[m].x1>>d[m].y1>>d[m].x2>>d[m].y2;
			d[m].flag=2;
			cin>>d[m].l;
			m++;
		}
		else
		{
			int x1,y1,x2,y2;
			cin>>x1>>y1>>x2>>y2;
			
			for(int i=y2;i>=y1;i--)
			{
				for(int j=x1;j<=x2;j++)
				{
					char o='.';
					for(int k=m-1;k>=0;k--)
					{
						if(d[k].flag==1)
						{
							if(check(j,i,d[k].x,d[k].y,d[k].r))
						    {
							    o=d[k].l;
							    break;
						    }
						}
						else if(d[k].flag==2)
						{
							if(check1(j,i,d[k].x1,d[k].y1,d[k].x2,d[k].y2))
							{
								o=d[k].l;
							    break;
							}					
						}		
					}
					cout<<o;
				}	
				cout<<endl;
			}	
		}
	}
	return 0;
}

L - Palm Island

Toph is playing a card game. She has n𝑛 cards and each card has a unique number of 1,2⋯n In this game, Toph can operate the deck of the cards. We may wish to assume that the cards from the top to the bottom of the deck are p1,p2,⋯pn (a permutation), then each operation must be one of the following two cases:

  1. Place the top card at the bottom of the deck, that is, change the order of the deck into p2,p3⋯pn,p1.
  2. Place the second card from the top at the bottom of the deck, that is, change the order of the deck into p1,p3⋯pn,p2

Now, you know that the initial order(from top to bottom) of Toph's deck is a1,a2,⋯an, and Toph wants to change the order of the deck into b1,b2,⋯bn after some operations. Please construct the operation sequence to help Toph implement the change.

Toph has no patience. So the number of operations should not exceed n2.

Input

The first line contains an integer T , indicating the number of test cases.

For each test case:

  • The first line contains an integer, n(3≤n≤1000), indicating the number of Toph's cards.
  • The second line contains n𝑛 integers a1,a2,⋯an, a permutation indicating the order of the deck initially.
  • The third line contains n𝑛 integers b1,b2,⋯bn, a permutation indicating the order of the deck want to make.

It is guaranteed that the sum of n𝑛 in T test cases is not exceed 1000.

Output

For each test case:

  • Output a line, which contains a string s1s2…sk(si∈{1,2}, 1≤i≤k) as your operation sequence. The length of the string should not exceed n2, or you will get "Wrong Answer".
  • If there are multiple solutions, output any of them.

Examples

InputcopyOutputcopy
2
3
1 2 3
2 3 1
4
1 2 3 4
2 1 3 4
1
112212

Note

If a1,a2⋯an and b1,b2⋯bn are the same in a test case, outputing an empty string is ok. But you should output an empty line in this situation.

DO NOT add extra space at the end of lines, or you will get "Wrong Answer" verdict.

 判断前后两个数,若前一个数大于后一个数,则输出2,并交换两个数的位置,否则输出1,最后一定会输出一个1。

#include<bits/stdc++.h>
#define int long long
#define IOS ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
using namespace std;
int a[1010],b[1010],c[1010];
signed main()
{
	IOS
	int t;
	cin>>t;
	while(t--)
	{
		int n;
		cin>>n;
		for(int i=0;i<n;i++)
		cin>>a[i];
		for(int i=0;i<n;i++)
		{
			cin>>b[i];
			c[b[i]]=i;
		}
		for(int i=0;i<n;i++)
		{
			for(int j=0;j<n-1;j++)
			{
				if(c[a[j]]>c[a[j+1]])
				{
					cout<<"2";
					swap(a[j],a[j+1]);
				}
				else cout<<"1";
			}
			cout<<"1";
		}
		cout<<endl;
	}
	return 0;
}

  • 16
    点赞
  • 20
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值