浙大月赛ZOJ Monthly, August 2014
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! 解题详见:寻找&星空の孩子比赛的时候没想到不知道怎么二分了。。。。。/悲剧! 加油!!!
浙大月赛ZOJ Monthly, August 2014的更多相关文章
- 135 - ZOJ Monthly, August 2014
135 - ZOJ Monthly, August 2014 A:构造问题,推断序列奇偶性.非常easy发现最小值不是1就是0.最大值不是n就是n - 1,注意细节去构造就可以 E:dp.dp[i][ ...
- ZOJ Monthly, August 2014
A Abs Problem http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemId=5330 找规律题,构造出解.copyright@ts ...
- 记次浙大月赛 134 - ZOJ Monthly, June 2014
链接 虽做出的很少,也记录下来,留着以后来补..浙大题目质量还是很高的 B 并查集的一些操作,同类和不同类我是根据到根节点距离的奇偶判断的,删点是直接新加一个点,记得福大月赛也做过类似的,并差集的这类 ...
- ZOJ Monthly, June 2014 月赛BCDEFGH题题解
比赛链接:点击打开链接 上来先搞了f.c,,然后发现状态不正确,一下午都是脑洞大开,, 无脑wa,无脑ce...一样的错犯2次.. 硬着头皮搞了几发,最后20分钟码了一下G,不知道为什么把1直接当成不 ...
- ZOJ Monthly, November 2014
做了一次月赛,没想到这么难,加上后来补上的题目也只有3个题.第一名也只有4个题啊啊啊啊~.其中两道还是水题.留坑慢慢补上来. 3832 Tilt Cylinder 给定如图所示有盖圆柱体,R,H,水面 ...
- 137 - ZOJ Monthly, November 2014 - J Poker Face
Poker Face Time Limit: 2 Seconds Memory Limit: 65536 KB As is known to all, coders are lack of ...
- ZOJ Monthly, June 2014 解题报告
A.Another Recurrence Sequence problemId=5287">B.Gears 题目大意:有n个齿轮,一開始各自为一组.之后进行m次操作,包含下面4种类型: ...
- Incircle and Circumcircle(二分+几何)浙大月赛zoj3806(详解版)图
Incircle and Circumcircle Time Limit: 2 Seconds Memory Limit: 65536 KB Special Judge A triangle is o ...
- ZOJ 4010 Neighboring Characters(ZOJ Monthly, March 2018 Problem G,字符串匹配)
题目链接 ZOJ Monthly, March 2018 Problem G 题意 给定一个字符串.现在求一个下标范围$[0, n - 1]$的$01$序列$f$.$f[x] = 1$表示存在一种 ...
随机推荐
- Color the ball(HDU1556)树状数组
每次对区间内气球进行一次染色,求n次操作后后所有气球染色次数. 树状数组,上下区间更新都可以,差别不大. 1.对于[x,y]区间,对第x-1位减1,第y位加1,之后向上统计 #include<b ...
- MySQL 5.6不删空用户的影响
目录 MySQL 5.6不删空用户的影响 问题 分析 测试 启动mysqld时没有加上--skip-name-resolve 启动mysqld时加上--skip-name-resolve 结论 MyS ...
- SubLime Text 3 配置SublimeREPL来交互式调试程序
1. 安装 SublimeREPL 插件 等待一下,输入sublimerepl,选择sublimeREPL,然后它就会在后台安装. 安装完之后,查看如下图 选择你要执行的*.py文件,通过这个路径,选 ...
- Python(27)--文件相关处理的应用(增、删、改、查)
文件名为message,文件内容如下: global log 127.0.0.1 local2 daemon maxconn 256 log 127.0.0.1 local2 info default ...
- Redis学习系列三List列表
一.简介 Redis中的列表相当于C#中的LinkedList,也就是链表,如果你研究过链表这个数据结构,肯定知道.它的插入和删除是非常快的,但是定位却很慢,因为必须遍历所有的元素,才能找到对应的值, ...
- 输入两棵二叉树A,B,判断B是不是A的子结构(c++实现)
#include <iostream> #include <cstdio> #include <stdio.h> #include <string> # ...
- Maven内置属性,pom属性
内置属性(Maven预定义,用户可以直接使用) ${basedir}表示项目根目录,即包含pom.xml文件的目录; ${version}表示项目版本; ${project.basedir}同${ba ...
- Shell脚本 | 性能测试之启动流量
安卓应用的流量统计有多种方式,点击「阅读原文」可以看到一篇别人写的文章,关于安卓流量数据的获取,写的挺全的,列举了几种不同方式的优劣.(见文末参考链接) 今天我要分享的是通过脚本一键获取应用的启动流量 ...
- java EE第一周博客
一,课程目标 能够完成javaee开发框架的深入学习,能够熟练的构建出基本开发框架,熟练掌握配置文件以及各种插件的应用.实现一个较为复杂的javaee项目 二.企业级应用与互联网应用的区别 企业级应用 ...
- Java中的简单工厂模式(转)
Java中的简单工厂模式 举两个例子以快速明白Java中的简单工厂模式: 女娲抟土造人话说:“天地开辟,未有人民,女娲抟土为人.”女娲需要用土造出一个个的人,但在女娲造出人之前,人的概念只存在于女娲的 ...