ACM-ICPC北京赛区2017网络同步赛 E+F

目录

E - Cats and Fish(模拟+思维)

F - Secret Poems(模拟+字符串处理+蛇形填数)


E - Cats and Fish(模拟+思维)

There are many homeless cats in PKU campus. They are all happy because the students in the cat club of PKU take good care of them. Li lei is one of the members of the cat club. He loves those cats very much. Last week, he won a scholarship and he wanted to share his pleasure with cats. So he bought some really tasty fish to feed them, and watched them eating with great pleasure. At the same time, he found an interesting question:

There are m fish and n cats, and it takes ci minutes for the ith cat to eat out one fish. A cat starts to eat another fish (if it can get one) immediately after it has finished one fish. A cat never shares its fish with other cats. When there are not enough fish left, the cat which eats quicker has higher priority to get a fish than the cat which eats slower. All cats start eating at the same time. Li Lei wanted to know, after x minutes, how many fish would be left.

Input

There are no more than 20 test cases.

For each test case:

The first line contains 3 integers: above mentioned m, n and x (0 < m <= 5000, 1 <= n <= 100, 0 <= x <= 1000).

The second line contains n integers c1,c2 … cn,  ci means that it takes the ith cat ci minutes to eat out a fish ( 1<= ci <= 2000).

Output

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

For each test case, print 2 integers p and q, meaning that there are p complete fish(whole fish) and q incomplete fish left after x minutes.

Sample Input

2 1 1
1
8 3 5
1 3 4
4 5 1
5 4 3 2 1

Sample Output

1 0
0 1
0 3

【题意】输入鱼的数量和猫的数量以及时间,以及每只猫吃掉一只鱼需要的时间,吃的快的在鱼不够的时候优先吃到鱼,问该时间后还剩下的完整的鱼和不完整的鱼的数量。

【分析】定义一个结构体,存每只猫吃鱼的时间和是否在吃的状态。然后按吃鱼的时间升序排序。遍历时间。如果当前这只猫没有在吃鱼,就给它一条鱼让它吃,如果这个时间可以让它吃完一条鱼,那么已经没有吃鱼了,状态标记为没吃。所以,对于每个时间点,只有该时间可以让它吃完一条鱼的时候才会eat标记为0,当某只猫标记为0说明上一秒它已经吃完一条鱼,就鱼的数量增加。最后剩下的完整的鱼的数量就是总的鱼的数量减去吃掉的。遍历每只猫,状态为正在吃的就是不完整的鱼的数量。

【代码】

#include<bits/stdc++.h>
using namespace std;

struct node{
	bool eat;
	int t;
}cat[105];
bool cmp(node x,node y)
{
	return x.t<y.t;
}

int main()
{
	int m,n,x;
	while(~scanf("%d%d%d",&m,&n,&x))
	{
		for(int i=1;i<=n;i++)
		{
			scanf("%d",&cat[i].t);
			cat[i].eat=false;
		} 
		sort(cat+1,cat+1+n,cmp);
		int p=m,q=0;
		for(int i=1;i<=x;i++)
		{
			for(int j=1;j<=n;j++)
			{
				if(cat[j].eat==false && p>0)//没有在吃并且鱼还有剩余 
				{
					p--;//分一条鱼给它,并且状态变成吃 
					cat[j].eat=true;	
				}
				if(i%cat[j].t==0)//该时间正好吃完一条鱼,下一秒状态即为false 
					cat[j].eat=false;
			}
		}
		for(int i=1;i<=n;i++)
			if(cat[i].eat==true)q++;
		cout<<p<<" "<<q<<endl;
	}
	return 0;
}

F - Secret Poems(模拟+字符串处理+蛇形填数)

The Yongzheng Emperor (13 December 1678 – 8 October 1735), was the fifth emperor of the Qing dynasty of China. He was a very hard-working ruler. He cracked down on corruption and his reign was known for being despotic, efficient, and vigorous.

Yongzheng couldn’t tolerate people saying bad words about Qing or him. So he started a movement called “words prison”. “Words prison” means literary inquisition. In the famous Zhuang Tinglong Case, more than 70 people were executed in three years because of the publication of an unauthorized history of the Ming dynasty.

In short, people under Yongzheng’s reign should be very careful if they wanted to write something. So some poets wrote poems in a very odd way that only people in their friends circle could read. This kind of poems were called secret poems.

A secret poem is a N×N matrix of characters which looks like random and meaning nothing. But if you read the characters in a certain order, you will understand it. The order is shown in figure 1 below:

            figure 1                                                           figure 2

Following the order indicated by arrows, you can get “THISISAVERYGOODPOEMITHINK”, and that can mean something.

But after some time, poets found out that some Yongzheng’s secret agent called “Mr. blood dripping” could read this kind of poems too. That was dangerous. So they introduced a new order of writing poems as shown in figure 2. And they wanted to convert the old poems written in old order as figure1 into the ones in new order. Please help them.

Input

There are no more than 10 test cases.

For each test case:

The first line is an integer N( 1 <= N <= 100), indicating that a poem is a N×N matrix which consist of capital letters.

Then N lines follow, each line is an N letters string. These N lines represent a poem in old order.

Output

For each test case, convert the poem in old order into a poem in new order.

Sample Input

5
THSAD 
IIVOP 
SEOOH 
RGETI 
YMINK
2
AB
CD
4
ABCD
EFGH
IJKL
MNOP

Sample Output

THISI
POEMS
DNKIA
OIHTV
OGYRE
AB
DC
ABEI
KHLF
NPOC
MJGD

【分析】模拟题吧

【代码】

#include<bits/stdc++.h>
using namespace std;

const int maxn=105;
char a[maxn][maxn],b[maxn*maxn],c[maxn][maxn];

int main()
{
	int n;
	while(~scanf("%d",&n))
	{
		memset(a,0,sizeof(a));
		memset(b,0,sizeof(b));
		memset(c,0,sizeof(c));
		for(int i=0;i<n;i++)scanf("%s",a[i]);
		int nn=2*n,cnt=0;
		for(int k=0;k<nn;k++)
		{
			if(k&1)//奇数
			{
				for(int i=0;i<n;i++)
					if(a[i][k-i])b[cnt++]=a[i][k-i];
			} 
			else
			{
				for(int i=k;i>=0;i--)
					if(a[i][k-i])b[cnt++]=a[i][k-i];
			} 
		}
		int tot=0,x=0,y=0;
		c[0][0]=b[0];//这里是c,不是a
		while(tot<n*n)//蛇形填数
		{
			while(y+1<n && !c[x][y+1])c[x][++y]=b[++tot];
			while(x+1<n && !c[x+1][y])c[++x][y]=b[++tot];
			while(x-1>=0 && !c[x-1][y])c[--x][y]=b[++tot];
			while(y-1>=0 && !c[x][y-1])c[x][--y]=b[++tot];
			if(tot==n*n-1)break;//注意减1
		}
		for(int i=0;i<n;i++)
		{
			for(int j=0;j<n;j++)
				printf("%c",c[i][j]);
			printf("\n");
		}
	}
	return 0;
} 

代码段 小部件 [Dàimǎ duàn xiǎo bùjiàn] Code section widget

[Dàimǎ duàn xiǎo bùjiàn [Dàimǎ duàn xiǎo bùjiàn] Code section widget]

Code section widget

[Dàimǎ duàn xiǎo bùjiàn]

Code section widget

 
 
 

猜你喜欢

转载自blog.csdn.net/qq_38735931/article/details/83548818