Abs Problem
Time Limit: 2 Seconds Memory Limit: 65536 KB Special Judge
Alice and Bob is playing a game, and this time the game is all about the absolute value!
Alice has N different positive integers, and each number is not greater than N. Bob has a lot of blank paper, and he is responsible for the calculation things. The rule of game is pretty simple. First, Alice chooses a number a1 from the N integers, and Bob will write it down on the first paper, that's b1. Then in the following kth rounds, Alice will choose a number ak (2 ≤ k ≤ N), then Bob will write the number bk=|ak-bk-1| on the kth paper. |x| means the absolute value of x.
Now Alice and Bob want to kown, what is the maximum and minimum value of bN. And you should tell them how to achieve that!
Input
The input consists of multiple test cases;
For each test case, the first line consists one integer N, the number of integers Alice have. (1 ≤ N ≤ 50000)
Output
For each test case, firstly print one line containing two numbers, the first one is the minimum value, and the second is the maximum value.
Then print one line containing N numbers, the order of integers that Alice should choose to achieve the minimum value. Then print one line containing N numbers, the order of integers that Alice should choose to achieve the maximum value.
Attention: Alice won't choose a integer more than twice.
Sample Input
2
Sample Output
1 1
1 2
2 1 题意:找出序列使b[n]最小和最大;
很容易发现最小值不是1就是0,最大值不是n就是n - 1;
又由于这是特殊判断题,So。。。
#include<stdio.h>
#include<math.h>
int main()
{
int N,i,j,max,min;
while(scanf("%d",&N)!=EOF)
{
min=N%;
max=(N-)%;
if(min==||min==)
min=;
else min=;
if(max==||max==)
max=;
else max=;
printf("%d %d\n",min,N-max); printf("%d",N);
for(i=N-; i>; i--)
printf(" %d",i);
printf("\n"); printf("%d",N-);
for(i=N-; i>; i--)
printf(" %d",i);
printf(" %d\n",N);
}
return ;
}
比赛的时候一直纠结与绝对值,没好好思考。。。真是太失败了!
加油!!!
Machine
Time Limit: 2 Seconds Memory Limit: 65536 KB
In a typical assembly line, machines are connected one by one. The first machine's output product will be the second machine's raw material. To simplify the problem, we put all machines into a two-dimension shelf. Every machine occupied exactly one grid and has two input ports and only one output port. One input port can get material from only one machine.
Pipes will be used to connect between these machines. There are two kinds of pipes : 'I' kind and 'L' kind. We should notice that the 'I' kind pipe can be linked one by one. Each pipe will also occupied one grid.
In Bob's factory, each machine will get raw materials from zero, one or two other machines. Some machines don't need any input materials, but any machine must have an output. Machines are coded by numbers from 1 to n. The output of the machines with greater code can be the input of the machines with less code. The machine NO.1's output product will be the final product, and will not be any other machine's input. Bob's factory has a shelf with infinite height, but finite width. He will give you the dependency relationship of these machines, and want you to arrange these machines and pipes so that he can minimize the width of the shelf.
Here's an example for you to help understand :
Products will falling from higher machine to lower machine through the pipes. Here, machine 1 gets materials from machine 2 and machine 3. The whole width of this system is 2.
Input
For each case, the first line will be an integer n indicates the number of the machines (2≤ n≤ 10000). The following line will include n-1 numbers. The i-th number ai means that the output of machine i+1 will be the input of machine ai (ai≤ i). The same code will be appeared at most twice. Notice machine 1's output will be the final output, and won't be any machine's input.
Output
For each case, we need exactly one integer as output, which is the minimal width of the shelf.
Sample Input
3
1 1
7
1 1 2 2 3 3
Sample Output
2
3
Hint
Case 1 is the example.
Case 2:
This problem contains massive input and output, please use efficient IO
methods.
题意:就是说有2种管子,管子的高度可以无限长,但宽度一致,问最小的宽度;输入第i个数表示第i+1个容器将要输向哪个容器;
思路:其实就是dfs,每次dfs下去,把子树宽度保存下来,然后找最大值,如果有多个,就是最大值+cnt宽度;
#include<stdio.h>
#include<string.h>
#include<vector>
using namespace std;
vector<int>map[];
int dp[];
void dfs(int p)
{
int i,j,flag,len;
len=map[p].size();
dp[p]=;
for(i=;i<len;i++)
{
j=map[p][i];
dfs(j);
if(dp[p]<dp[j])flag=dp[j];//取大流
else if(dp[p]==dp[j])flag=dp[p]+;
dp[p]=flag;
}
if(dp[p]==)dp[p]=;
}
int main()
{
int n,a;
while(scanf("%d",&n)>)
{
for(int i=;i<=n;i++)map[i].clear();
for(int i=;i<=n;i++)
{
scanf("%d",&a);
map[a].push_back(i);
}
dfs();
printf("%d\n",dp[]);
}
}
比赛的时候也没做出来,总是WA原因是找分支的时候应该取大的;
加油!!!
YY's Minions
Time Limit: 2 Seconds Memory Limit: 65536 KB
Despite YY's so much homework, she would like to take some time to play with her minions first.
YY lines her minions up to an N*M matrix. Every minion has two statuses: awake or asleep. We use 0(the digit) to represent that it is asleep, and 1 for awake. Also, we define the minions who are around a minion closest in one of the eight directions its neighbors. And every minute every minion will change its status by the following specific rules:
- If this minion is awake, and the number of its neighbors who are awake is less than 2, this minion will feel lonely and turn to asleep.
- If this minion is awake, and the number of its neighbors who are awake is more than 3, this minion will turn to asleep for it will feel too crowded.
- If this minion is awake, and the number of its neighbors who are awake is exactly 2 or 3, this minion will keep being awake and feel very happy.
- If this minion is asleep, and the number of its neighbors who are awake is exactly 3, this minion will wake up because of the noise. Note that all changes take place at the same time at the beginning of a specific minute.
Also, some minions will get bored and leave this silly game. We use 'X's to describe them. We suppose that a minion would leave after T minutes. It will leave at the end of the Tth minute. Its status is considered during the change at the beginning of the Tth minute, and should be ignored after that. Of course, one minion will not leave twice!
YY is a girl full of curiosity and wants to know every minion's status after F minutes. But you know she is weak and lazy! Please help this cute girl to solve this problem :)
Input
There are multiple test cases.
The first line contains the number of test cases Q. 1<=Q<=100.
For each case, there are several lines:
The
first line contains four integers N, M, F,
K. K means the number of leaving messages.
1<=N, M<=50, 1<=F<=1000,
1<=K<=N*M.
Next N lines are the matrix which
shows the initial status of each minion. Each line contains M chars.
We guarantee that 'X' wouldn't appear in initial status matrix.
And next
K lines are the leaving messages. Each line contains three integers
Ti, Xi, Yi,
They mean the minion who is located in (Xi,
Yi) will leave the game at the end of the
Tith minutes.
1<=Ti<= F,
1<=Xi<=N,
1<=Yi<=M.Output
For each case, output N lines as a matrix which shows the status
of each minion after F minutes.Sample Input
2
3 3 2 1
101
110
001
1 2 2
5 5 6 3
10111
01000
00000
01100
10000
2 3 3
2 4 1
5 1 5Sample Output
010
1X0
010
0000X
11000
00X00
X0000
00000Hint
For case 1:
T=0, the game starts
101
110
001
---------------
at the beginning of T=1, a change took place
100
101
010
---------------
at the end of T=1 (the minion in (2,2) left)
100
1X1
010
---------------
at the beginning of T=2, a change took place
010
1X0
010
---------------
at the end of T=2 (nothing changed for no minion left at T=2)
010
1X0
010
Author: XIAO, Zimu
Source: ZOJ Monthly, August
2014
模拟题;按照说的做就好了。
#include<iostream>
#include<cstring>
#include<cstdio>
#include<algorithm>
using namespace std;
char str[][];
int a[][],aa[][];
int t[],x[],y[];
int d[][]= {{,},{,},{,-},{,},{,-},{-,},{-,},{-,-}};
int main()
{
int q,n,m,f,k,r,e;
int i,j,cnt,c;
scanf("%d",&q);
while(q--)
{
memset(a,,sizeof(a));
memset(t,,sizeof(t));
memset(x,,sizeof(x));
memset(y,,sizeof(y));
memset(str,,sizeof(str));
scanf("%d%d%d%d",&n,&m,&f,&k);
getchar();
for(i=; i<n; i++)
{
for(j=; j<m; j++)
scanf("%c",&str[i][j]);
getchar();
} for(i=; i<n; i++)
{
for(j=; j<m; j++)
{
if(str[i][j]=='')
a[i][j]=;
if(str[i][j]=='')
a[i][j]=;
}
} for(i=; i<k; i++)
scanf("%d%d%d",&t[i],&x[i],&y[i]);
for(r=; r<=f; r++)
{
memset(aa,,sizeof(aa));
for(i=; i<n; i++)
{
for(j=; j<m; j++)
{
if(a[i][j]==)
{
for(e=;e<;e++)
{
int xx=i+d[e][];
int yy=j+d[e][];
if(xx>=&&yy>=&&xx<n&&yy<m&&a[xx][yy]!=)
aa[xx][yy]++;
}
}
}
}
for(i=; i<n; i++)
{
for(j=; j<m; j++)
{
if(a[i][j]==)
continue;
if(a[i][j]==)
{
if(aa[i][j]<||aa[i][j]>)
a[i][j]=;
}
else if(a[i][j]==)
{
if(aa[i][j]==)
a[i][j]=;
}
}
}
for(i=;i<k;i++)
{
if(r==t[i])
a[x[i]-][y[i]-]=;
}
}
for(i=; i<n; i++)
{
for(j=; j<m; j++)
{
if(a[i][j]==)
printf("X");
else
printf("%d",a[i][j]);
}
printf("\n");
}
}
return ;
}
比赛的时候都木有看题目 /哭
加油!!!
Incircle and Circumcircle
Time Limit: 2 Seconds Memory Limit: 65536 KB Special Judge
A triangle is one the basic shapes in geometry. It's a polygon with three vertices and three sides which are line segments. A triangle with vertices A, B, C is denoted ΔABC. And its three sides, BC, CA, AB are often denoted a, b and c.
The incircle of a triangle is the largest circle contained in the triangle, it is tangent to the three sides. The center of the incircle is called the triangle's incenter and the radius of the incircle is called inradius, which is denoted r.
The circumcircle of a triangle is the circle which passes through all its three vertices. The center of the this circle is called circumcenter and its radius is called circumradius, which is denoted R.
It's very easy to calculate r and R after knowing a, b and c. Now you are given r and R, can you calculate a valid triple (a, b, c)?
Input
There are multiple cases. Each case has two positive integers r and R in one line. (r and R are less than 105)
Ouput
For each case, print three floating numbers a, b and c in one line if it's possible to get r and R. If there are no possible tuples, print "NO Solution!".
The judge program uses your a, b and c to calculate the inradius and circumradius. Only the relative error of your inradius and circumradius less than 10-8 will be accepted.
Sample Input
1 2
2 5
9 9
Sample Ouput
3.464101615137754587 3.464101615137754587 3.464101615137754587
6 8 10
NO Solution! 解题详见:寻找&星空の孩子比赛的时候没想到不知道怎么二分了。。。。。/悲剧! 加油!!!