BUAA-SCSE Training day1

小学期-计组实验

的确像学长说的认真做会有收获

今天老师检查的时候发现自己好多地方没有掌握

明天去好好看一看


大一开了算法提高班

好想去参加。。。

自己的基础实在是太差

有没有说什么都放下专心的搞算法

一直都是处于这样不尴不尬的境地

感觉昂神这个算法提高班的题目好像杭电的acm steps

刷起来蛮有感觉的。。

虽然好多题目不会。。


刚刚回宿舍水了一发贪心

Pe了一万遍

实在是不想开新题了

半总结半休息一下吧

BUAA-SCSE Training day1

A - Way Too Long Words
Time Limit:2000MS     Memory Limit:262144KB     64bit IO Format:%I64d & %I64u

Description

Sometimes some words like "localization" or "internationalization" are so long that writing them many times in one text is quite tiresome.

Let's consider a word too long, if its length is strictly more than 10 characters. All too long words should be replaced with a special abbreviation.

This abbreviation is made like this: we write down the first and the last letter of a word and between them we write the number of letters between the first and the last letters. That number is in decimal system and doesn't contain any leading zeroes.

Thus, "localization" will be spelt as "l10n", and "internationalization» will be spelt as "i18n".

You are suggested to automatize the process of changing the words with abbreviations. At that all too long words should be replaced by the abbreviation and the words that are not too long should not undergo any changes.

Input

The first line contains an integer n (1 ≤ n ≤ 100). Each of the following n lines contains one word. All the words consist of lowercase Latin letters and possess the lengths of from 1 to 100 characters.

Output

Print n lines. The i-th line should contain the result of replacing of the i-th word from the input data.

Sample Input

Input
4
word
localization
internationalization
pneumonoultramicroscopicsilicovolcanoconiosis
Output
word
l10n
i18n
p43s


#include<iostream>
#include<cstdio>
#include<cstring>
#include<cstdlib>
using namespace std;
int main()
{
	int T;
	cin>>T;
	while(T--)
	{
		char s[105];
		cin>>s;
		int len=strlen(s);
		if(len<=10)
		{
			cout<<s<<endl;
		}
		else
		{
			cout<<s[0]<<len-2<<s[len-1]<<endl;
		}
	}
//	system("pause");
	return 0;
}

B - Games
Time Limit:1000MS     Memory Limit:262144KB     64bit IO Format:%I64d & %I64u

Description

Manao works on a sports TV. He's spent much time watching the football games of some country. After a while he began to notice different patterns. For example, each team has two sets of uniforms: home uniform and guest uniform. When a team plays a game at home, the players put on the home uniform. When a team plays as a guest on somebody else's stadium, the players put on the guest uniform. The only exception to that rule is: when the home uniform color of the host team matches the guests' uniform, the host team puts on its guest uniform as well. For each team the color of the home and guest uniform is different.

There are n teams taking part in the national championship. The championship consists of n·(n - 1) games: each team invites each other team to its stadium. At this point Manao wondered: how many times during the championship is a host team going to put on the guest uniform? Note that the order of the games does not affect this number.

You know the colors of the home and guest uniform for each team. For simplicity, the colors are numbered by integers in such a way that no two distinct colors have the same number. Help Manao find the answer to his question.

Input

The first line contains an integer n (2 ≤ n ≤ 30). Each of the following n lines contains a pair of distinct space-separated integers hiai(1 ≤ hi, ai ≤ 100) — the colors of the i-th team's home and guest uniforms, respectively.

Output

In a single line print the number of games where the host team is going to play in the guest uniform.

Sample Input

Input
3
1 2
2 4
3 4
Output
1
Input
4
100 42
42 100
5 42
100 5
Output
5
Input
2
1 2
1 2
Output
0

Hint

In the first test case the championship consists of 6 games. The only game with the event in question is the game between teams 2 and 1 on the stadium of team 2.

In the second test sample the host team will have to wear guest uniform in the games between teams: 1 and 2, 2 and 1, 2 and 3, 3 and 4, 4 and 2 (the host team is written first).



#include<iostream>
using namespace std;
int main()
{
	int T;
	int n;
	cin>>n;
	int a[105];
	int b[105];
	for(int i=0;i<n;i++)
	{
		cin>>a[i]>>b[i];
	}
	int cnt=0;
	for(int i=0;i<n;i++)
	{
		for(int j=0;j<n;j++)
		{
			if(a[i]==b[j])
			{
				cnt++;
			}
		}
	}
	cout<<cnt<<endl;
//	system("pause");
	return 0;
}
C - Beautiful Matrix
Time Limit:2000MS     Memory Limit:262144KB     64bit IO Format:%I64d & %I64u

Description

You've got a 5 × 5 matrix, consisting of 24 zeroes and a single number one. Let's index the matrix rows by numbers from 1 to 5 from top to bottom, let's index the matrix columns by numbers from 1 to 5 from left to right. In one move, you are allowed to apply one of the two following transformations to the matrix:

  1. Swap two neighboring matrix rows, that is, rows with indexes i and i + 1 for some integer i (1 ≤ i < 5).
  2. Swap two neighboring matrix columns, that is, columns with indexes j and j + 1 for some integer j (1 ≤ j < 5).

You think that a matrix looks beautiful, if the single number one of the matrix is located in its middle (in the cell that is on the intersection of the third row and the third column). Count the minimum number of moves needed to make the matrix beautiful.

Input

The input consists of five lines, each line contains five integers: the j-th integer in the i-th line of the input represents the element of the matrix that is located on the intersection of the i-th row and the j-th column. It is guaranteed that the matrix consists of 24 zeroes and a single number one.

Output

Print a single integer — the minimum number of moves needed to make the matrix beautiful.

Sample Input

Input
0 0 0 0 0
0 0 0 0 1
0 0 0 0 0
0 0 0 0 0
0 0 0 0 0
Output
3
Input
0 0 0 0 0
0 0 0 0 0
0 1 0 0 0
0 0 0 0 0
0 0 0 0 0
Output
1


#include<iostream>
#include<cmath>
using namespace std;
int main()
{
	int a[10][10];
	int ans=0;
	for(int i=1;i<=5;i++)
	{
		for(int j=1;j<=5;j++)
		{
			cin>>a[i][j];
			if(a[i][j]==1)
			{
				ans=abs(i-3)+abs(j-3);
			}
		}
	}
	cout<<ans<<endl;
//	system("pause");
	return 0;
}
D - Fancy Fence
Time Limit:2000MS     Memory Limit:262144KB     64bit IO Format:%I64d & %I64u

Description

Emuskald needs a fence around his farm, but he is too lazy to build it himself. So he purchased a fence-building robot.

He wants the fence to be a regular polygon. The robot builds the fence along a single path, but it can only make fence corners at a single angle a.

Will the robot be able to build the fence Emuskald wants? In other words, is there a regular polygon which angles are equal to a?

Input

The first line of input contains an integer t (0 < t < 180) — the number of tests. Each of the following t lines contains a single integer a(0 < a < 180) — the angle the robot can make corners at measured in degrees.

Output

For each test, output on a single line "YES" (without quotes), if the robot can build a fence Emuskald wants, and "NO" (without quotes), if it is impossible.

Sample Input

Input
3
30
60
90
Output
NO
YES
YES

Hint

In the first test case, it is impossible to build the fence, since there is no regular polygon with angle .

In the second test case, the fence is a regular triangle, and in the last test case — a square.



数学渣木有办法。。

/*
稍微转个弯
内角和(n-2)*180=nx;
那么n(180-x)=360
于是只要判断360%(180-x)==0即可
*/
 
#include<iostream>
using namespace std;
int main()
{
	int T;
	cin>>T;
	while(T--)
	{
		int x;
		cin>>x;
		if(360%(180-x)==0)
		{
			cout<<"YES"<<endl;
		}
		else
		{
			cout<<"NO"<<endl;
		}
	}
//	system("pause");
	return 0;
}

E - System Administrator
Time Limit:2000MS     Memory Limit:262144KB     64bit IO Format:%I64d & %I64u

Description

Polycarpus is a system administrator. There are two servers under his strict guidance — a and b. To stay informed about the servers' performance, Polycarpus executes commands "ping a" and "ping b". Each ping command sends exactly ten packets to the server specified in the argument of the command. Executing a program results in two integers x and y (x + y = 10; x, y ≥ 0). These numbers mean that xpackets successfully reached the corresponding server through the network and y packets were lost.

Today Polycarpus has performed overall n ping commands during his workday. Now for each server Polycarpus wants to know whether the server is "alive" or not. Polycarpus thinks that the server is "alive", if at least half of the packets that we send to this server reached it successfully along the network.

Help Polycarpus, determine for each server, whether it is "alive" or not by the given commands and their results.

Input

The first line contains a single integer n (2 ≤ n ≤ 1000) — the number of commands Polycarpus has fulfilled. Each of the following nlines contains three integers — the description of the commands. The i-th of these lines contains three space-separated integers tixiyi(1 ≤ ti ≤ 2; xi, yi ≥ 0; xi + yi = 10). If ti = 1, then the i-th command is "ping a", otherwise the i-th command is "ping b". Numbers xi,yi represent the result of executing this command, that is, xi packets reached the corresponding server successfully and yi packets were lost.

It is guaranteed that the input has at least one "ping a" command and at least one "ping b" command.

Output

In the first line print string "LIVE" (without the quotes) if server a is "alive", otherwise print "DEAD" (without the quotes).

In the second line print the state of server b in the similar format.

Sample Input

Input
2
1 5 5
2 6 4
Output
LIVE
LIVE
Input
3
1 0 10
2 0 10
1 10 0
Output
LIVE
DEAD

Hint

Consider the first test case. There 10 packets were sent to server a, 5 of them reached it. Therefore, at least half of all packets sent to this server successfully reached it through the network. Overall there were 10 packets sent to server b, 6 of them reached it. Therefore, at least half of all packets sent to this server successfully reached it through the network.

Consider the second test case. There were overall 20 packages sent to server a, 10 of them reached it. Therefore, at least half of all packets sent to this server successfully reached it through the network. Overall 10 packets were sent to server b, 0 of them reached it. Therefore, less than half of all packets sent to this server successfully reached it through the network.


#include<iostream>
using namespace std;
int main()
{
	int n;
	int a=0;
	int b=0;
	cin>>n;
	for(int i=0;i<n;i++)
	{
		int flag;
		cin>>flag;
		int x,y;
		if(flag==1)
		{
			cin>>x>>y;
			a+=x-y;
		}
		else
		{
			cin>>x>>y;
			b+=x-y;
		}
	}
	if(a>=0)
	{
		cout<<"LIVE"<<endl;
	}
	else
	{
		cout<<"DEAD"<<endl;
	}
	if(b>=0)
	{
		cout<<"LIVE"<<endl;
	}
	else
	{
		cout<<"DEAD"<<endl;
	}
//	system("pause");
	return 0;
}
	
F - Cosmic Tables
Time Limit:3000MS     Memory Limit:262144KB     64bit IO Format:%I64d & %I64u

Description

The Free Meteor Association (FMA) has got a problem: as meteors are moving, the Universal Cosmic Descriptive Humorous Program (UCDHP) needs to add a special module that would analyze this movement.

UCDHP stores some secret information about meteors as an n × m table with integers in its cells. The order of meteors in the Universe is changing. That's why the main UCDHP module receives the following queries:

  • The query to swap two table rows;
  • The query to swap two table columns;
  • The query to obtain a secret number in a particular table cell.

As the main UCDHP module is critical, writing the functional of working with the table has been commissioned to you.

Input

The first line contains three space-separated integers nm and k (1 ≤ n, m ≤ 10001 ≤ k ≤ 500000) — the number of table columns and rows and the number of queries, correspondingly.

Next n lines contain m space-separated numbers each — the initial state of the table. Each number p in the table is an integer and satisfies the inequality 0 ≤ p ≤ 106.

Next k lines contain queries in the format "si xi yi", where si is one of the characters "с", "r" or "g", and xiyi are two integers.

  • If si = "c", then the current query is the query to swap columns with indexes xi and yi (1 ≤ x, y ≤ m, x ≠ y);
  • If si = "r", then the current query is the query to swap rows with indexes xi and yi (1 ≤ x, y ≤ n, x ≠ y);
  • If si = "g", then the current query is the query to obtain the number that located in the xi-th row and in the yi-th column (1 ≤ x ≤ n, 1 ≤ y ≤ m).

The table rows are considered to be indexed from top to bottom from 1 to n, and the table columns — from left to right from 1 to m.

Output

For each query to obtain a number (si = "g") print the required number. Print the answers to the queries in the order of the queries in the input.

Sample Input

Input
3 3 5
1 2 3
4 5 6
7 8 9
g 3 2
r 3 2
c 2 3
g 2 2
g 3 2
Output
8
9
6
Input
2 3 3
1 2 4
3 1 5
c 2 1
r 1 2
g 1 3
Output
5

Hint

Let's see how the table changes in the second test case.

After the first operation is fulfilled, the table looks like that:

2 1 4

1 3 5

After the second operation is fulfilled, the table looks like that:

1 3 5

2 1 4

So the answer to the third query (the number located in the first row and in the third column) will be 5.



做题没有分析复杂度

明显应该离线搞

/*
常规模拟tle
并不是对每次swap都需要进行操作
用c[]和r[]记录行和列的交换情况即可
另外cin & cout tle 
*/
#include<iostream>
#include<cstdio>
#include<cstring>
#include<cstdlib>
using namespace std;
int a[1005][1005];
int r[1005];//标记行交换情况 
int c[1005];//标记列交换情况 
int main()
{
	int n,m,k;
	cin>>n>>m>>k;
	for(int i=1;i<=n;i++)
	{
		r[i]=i;
	}
	for(int i=1;i<=m;i++)
	{
		c[i]=i;
	} 
	for(int i=1;i<=n;i++)
	{
		for(int j=1;j<=m;j++)
		{
			scanf("%d",&a[i][j]);
		}
	}
	while(k--)
	{
//		cout<<r[1]<<endl<<c[3]<<endl;
		char str[5];
		int x,y;
		scanf("%s%d%d",str,&x,&y);
		if(str[0]=='g')
		{
			printf("%d\n",a[r[x]][c[y]]);
		}
		else if(str[0]=='r')
		{
			int temp=r[x];
			r[x]=r[y];
			r[y]=temp;
		}
		else
		{
			int temp=c[x];
			c[x]=c[y];
			c[y]=temp;
		}
	}
//	system("pause");
	return 0;
}
	

G - Sereja and Bottles
Time Limit:2000MS     Memory Limit:262144KB     64bit IO Format:%I64d & %I64u

Description

Sereja and his friends went to a picnic. The guys had n soda bottles just for it. Sereja forgot the bottle opener as usual, so the guys had to come up with another way to open bottles.

Sereja knows that the i-th bottle is from brand ai, besides, you can use it to open other bottles of brand bi. You can use one bottle to open multiple other bottles. Sereja can open bottle with opened bottle or closed bottle.

Knowing this, Sereja wants to find out the number of bottles they've got that they won't be able to open in any way. Help him and find this number.

Input

The first line contains integer n(1 ≤ n ≤ 100) — the number of bottles. The next n lines contain the bottles' description. The i-th line contains two integers ai, bi(1 ≤ ai, bi ≤ 1000) — the description of the i-th bottle.

Output

In a single line print a single integer — the answer to the problem.

Sample Input

Input
4
1 1
2 2
3 3
4 4
Output
4
Input
4
1 2
2 3
3 4
4 1
Output
0


/*
好晦涩难懂的题。。。。
*/
#include<iostream>
#include<cstring>
#include<cstdlib>
#include<cstdio>
using namespace std;
int mark[105];
int a[105],b[105];
int main()
{
    int n;
    cin>>n;
    for(int i=0;i<n;i++)
    {
		cin>>a[i]>>b[i];
	}
    memset(mark,1,sizeof(mark));
    for(int i=0;i<n;i++)
    {
		for(int j=0;j<n;j++)
        {
			if(i!=j&&b[i]==a[j])
			{
                mark[j]=0;
			}
		}
	}
    int ans=0;
    for(int i=0;i<n;i++)
    {
		if(mark[i])
		{
            ans++;
		}
	}
    cout<<ans<<endl;
//  system("pause");
    return 0;
}
H - Queue at the School
Time Limit:2000MS     Memory Limit:262144KB     64bit IO Format:%I64d & %I64u

Description

During the break the schoolchildren, boys and girls, formed a queue of n people in the canteen. Initially the children stood in the order they entered the canteen. However, after a while the boys started feeling awkward for standing in front of the girls in the queue and they started letting the girls move forward each second.

Let's describe the process more precisely. Let's say that the positions in the queue are sequentially numbered by integers from 1 to n, at that the person in the position number 1 is served first. Then, if at time x a boy stands on the i-th position and a girl stands on the (i + 1)-th position, then at time x + 1 the i-th position will have a girl and the (i + 1)-th position will have a boy. The time is given in seconds.

You've got the initial position of the children, at the initial moment of time. Determine the way the queue is going to look after t seconds.

Input

The first line contains two integers n and t (1 ≤ n, t ≤ 50), which represent the number of children in the queue and the time after which the queue will transform into the arrangement you need to find.

The next line contains string s, which represents the schoolchildren's initial arrangement. If the i-th position in the queue contains a boy, then the i-th character of string s equals "B", otherwise the i-th character equals "G".

Output

Print string a, which describes the arrangement after t seconds. If the i-th position has a boy after the needed time, then the i-th charactera must equal "B", otherwise it must equal "G".

Sample Input

Input
5 1
BGGBG
Output
GBGGB
Input
5 2
BGGBG
Output
GGBGB
Input
4 1
GGGB
Output
GGGB


#include<iostream>
#include<cstdio>
#include<cstring>
#include<cstdlib>
using namespace std;
int main()
{
	int n,t;
	cin>>n>>t;
	char str[55];
	cin>>str;
	int len=strlen(str);
	for(int i=1;i<=t;i++)
	{
		for(int j=0;j<len-1;j++)
		{
			if(str[j]=='B'&&str[j+1]=='G')
			{
				str[j]='G';
				str[j+1]='B';
				j++;
			}
		}
	}
	cout<<str<<endl;
//	system("pause");
	return 0;
}
		
I - Present to Lyb
Time Limit:5000MS     Memory Limit:262144KB     64bit IO Format:%I64d & %I64u

Description

One day Petya got a set of wooden cubes as a present from his mom. Petya immediately built a whole city from these cubes.

The base of the city is an n × n square, divided into unit squares. The square's sides are parallel to the coordinate axes, the square's opposite corners have coordinates (0, 0) and (n, n). On each of the unit squares Petya built a tower of wooden cubes. The side of a wooden cube also has a unit length.

After that Petya went an infinitely large distance away from his masterpiece and looked at it in the direction of vector v = (vx, vy, 0). Petya wonders, how many distinct cubes are visible from this position. Help him, find this number.

Each cube includes the border. We think that a cube is visible if there is a ray emanating from some point p, belonging to the cube, in the direction of vector  - v, that doesn't contain any points, belonging to other cubes.

Input

The first line contains three integers nvx and vy (1 ≤ n ≤ 103|vx|, |vy| ≤ |104||vx| + |vy| > 0).

Next n lines contain n integers each: the j-th integer in the i-th line aij (0 ≤ aij ≤ 1091 ≤ i, j ≤ n) represents the height of the cube tower that stands on the unit square with opposite corners at points (i - 1, j - 1) and (i, j).

Output

Print a single integer — the number of visible cubes.

Please, do not use the %lld specifier to read or write 64-bit integers in С++. It is preferred to use the cincout streams or the %I64dspecifier.

Sample Input

Input
5 -1 2
5 0 0 0 1
0 0 0 0 2
0 0 0 1 2
0 0 0 0 2
2 2 2 2 3
Output
20
Input
5 1 -2
5 0 0 0 1
0 0 0 0 2
0 0 0 1 2
0 0 0 0 2
2 2 2 2 3
Output
15

这种to lyb大神的题明显不是我这种菜可以涉足的。。。




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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值