Wunder Fund Round 2016 (Div. 1 + Div. 2 combined) 总结
2016-01-30 23:25
465 查看
A. Slime Combining
time limit per test
2 seconds
memory limit per test
256 megabytes
input
standard input
output
standard output
Your friend recently gave you some slimes for your birthday. You have n slimes all initially with value 1.
You are going to play a game with these slimes. Initially, you put a single slime by itself in a row. Then, you will add the other n - 1 slimes
one by one. When you add a slime, you place it at the right of all already placed slimes. Then, while the last two slimes in the row have the same value v,
you combine them together to create a slime with value v + 1.
You would like to see what the final state of the row is after you've added all n slimes. Please print the values of the
slimes in the row from left to right.
Input
The first line of the input will contain a single integer, n (1 ≤ n ≤ 100 000).
Output
Output a single line with k integers, where k is
the number of slimes in the row after you've finished the procedure described in the problem statement. The i-th of these numbers should be the value
of the i-th slime from the left.
Sample test(s)
input
output
input
output
input
output
input
output
Note
In the first sample, we only have a single slime with value 1. The final state of the board is just a single slime with value 1.
In the second sample, we perform the following steps:
Initially we place a single slime in a row by itself. Thus, row is initially 1.
Then, we will add another slime. The row is now 1 1. Since two rightmost slimes have the same values, we should replace these slimes with one with
value 2. Thus, the final state of the board is 2.
In the third sample, after adding the first two slimes, our row is 2. After adding one more slime, the row becomes 21.
In the last sample, the steps look as follows:
122 133 13 23 2 14直接水过吧,没啥好说的
B. Guess the Permutation
time limit per test
2 seconds
memory limit per test
256 megabytes
input
standard input
output
standard output
Bob has a permutation of integers from 1 to n. Denote
this permutation as p. The i-th element
of p will be denoted as pi.
For all pairs of distinct integers i, j between 1 and n,
he wrote the number ai, j = min(pi, pj).
He writes ai, i = 0 for
all integer i from 1 to n.
Bob gave you all the values of ai, j that
he wrote down. Your job is to reconstruct any permutation that could have generated these values. The input will be formed so that it is guaranteed that there is at least one solution that is consistent with the information given.
Input
The first line of the input will contain a single integer n (2 ≤ n ≤ 50).
The next n lines will contain the values of ai, j.
The j-th number on the i-th line will represent ai, j.
The i-th number on the i-th line will be0.
It's guaranteed that ai, j = aj, i and
there is at least one solution consistent with the information given.
Output
Print n space separated integers, which represents a permutation that could have generated these values. If there are multiple possible solutions, print
any of them.
Sample test(s)
input
output
input
output
Note
In the first case, the answer can be {1, 2} or {2, 1}.
In the second case, another possible answer is {2, 4, 5, 1, 3}.
题意:给你一个数字n,然后1-n数字之间有很多排列,求得一个排列,使得ai, j = min(pi, pj).(a[i][j]为矩阵中的值)
解:我的做法是求矩阵中每一行或列中有多少个不同的数字(0除外),为1的就是mi++(mi初始值为1),其他的每行个数-1.
time limit per test
2 seconds
memory limit per test
256 megabytes
input
standard input
output
standard output
Your friend recently gave you some slimes for your birthday. You have n slimes all initially with value 1.
You are going to play a game with these slimes. Initially, you put a single slime by itself in a row. Then, you will add the other n - 1 slimes
one by one. When you add a slime, you place it at the right of all already placed slimes. Then, while the last two slimes in the row have the same value v,
you combine them together to create a slime with value v + 1.
You would like to see what the final state of the row is after you've added all n slimes. Please print the values of the
slimes in the row from left to right.
Input
The first line of the input will contain a single integer, n (1 ≤ n ≤ 100 000).
Output
Output a single line with k integers, where k is
the number of slimes in the row after you've finished the procedure described in the problem statement. The i-th of these numbers should be the value
of the i-th slime from the left.
Sample test(s)
input
1
output
1
input
2
output
2
input
3
output
2 1
input
8
output
4
Note
In the first sample, we only have a single slime with value 1. The final state of the board is just a single slime with value 1.
In the second sample, we perform the following steps:
Initially we place a single slime in a row by itself. Thus, row is initially 1.
Then, we will add another slime. The row is now 1 1. Since two rightmost slimes have the same values, we should replace these slimes with one with
value 2. Thus, the final state of the board is 2.
In the third sample, after adding the first two slimes, our row is 2. After adding one more slime, the row becomes 21.
In the last sample, the steps look as follows:
122 133 13 23 2 14直接水过吧,没啥好说的
#include<stdio.h>
#include<string.h>
#include<algorithm>
using namespace std;
#define LL __int64LL p(LL x,LL y)
{
LL sum=1;
for(LL i=1;i<=y;i++)
{
sum*=x;
}
return sum;
}
LL N(LL x)
{
LL cnt=0;
while(x)
{
x/=2;
cnt++;
}
return cnt;
}
int main()
{
LL n;
while(scanf("%I64d",&n)!=EOF)
{
LL t=n;
while(t)
{
LL cnt=N(t);
printf("%I64d ",cnt);
t=t-p(2,cnt-1);
}
printf("\n");
}
return 0;
}
B. Guess the Permutation
time limit per test
2 seconds
memory limit per test
256 megabytes
input
standard input
output
standard output
Bob has a permutation of integers from 1 to n. Denote
this permutation as p. The i-th element
of p will be denoted as pi.
For all pairs of distinct integers i, j between 1 and n,
he wrote the number ai, j = min(pi, pj).
He writes ai, i = 0 for
all integer i from 1 to n.
Bob gave you all the values of ai, j that
he wrote down. Your job is to reconstruct any permutation that could have generated these values. The input will be formed so that it is guaranteed that there is at least one solution that is consistent with the information given.
Input
The first line of the input will contain a single integer n (2 ≤ n ≤ 50).
The next n lines will contain the values of ai, j.
The j-th number on the i-th line will represent ai, j.
The i-th number on the i-th line will be0.
It's guaranteed that ai, j = aj, i and
there is at least one solution consistent with the information given.
Output
Print n space separated integers, which represents a permutation that could have generated these values. If there are multiple possible solutions, print
any of them.
Sample test(s)
input
20 11 0
output
2 1
input
5
0 2 2 1 22 0 4 1 32 4 0 1 31 1 1 0 12 3 3 1 0
output
2 5 4 1 3
Note
In the first case, the answer can be {1, 2} or {2, 1}.
In the second case, another possible answer is {2, 4, 5, 1, 3}.
题意:给你一个数字n,然后1-n数字之间有很多排列,求得一个排列,使得ai, j = min(pi, pj).(a[i][j]为矩阵中的值)
解:我的做法是求矩阵中每一行或列中有多少个不同的数字(0除外),为1的就是mi++(mi初始值为1),其他的每行个数-1.
#include<stdio.h> #include<string.h> #include<algorithm> using namespace std; const int maxm=1e2+20; int p[maxm]; int a[maxm][maxm]; int x[maxm][maxm]; int b[maxm]; int vis[maxm]; int vit[maxm]; int main() { int n; while(scanf("%d",&n)!=EOF) { for(int i=0;i<n;i++) { memset(vis,0,sizeof(vis)); for(int j=0;j<n;j++) { scanf("%d",&a[i][j]); if(a[i][j]!=0&&!vis[a[i][j]]) { b[i]++; vis[a[i][j]]=1; } } } int t=n; int mi=1,ma=n; memset(vit,0,sizeof(vit)); while(t) { for(int i=0;i<n;i++) { if(b[i]==1&&!vit[i]) { p[i]=mi++; vit[i]=1; } } for(int i=0;i<n;i++) { b[i]--; } t--; } for(int i=0;i<n;i++) { printf("%d ",p[i]); } printf("\n"); } return 0; }
相关文章推荐
- 配置中心
- 互联网老炮温京军:当“美妆领域”遇上“外资制造”
- centos shell编程6一些工作中实践脚本 nagios监控脚本 自定义zabbix脚本 mysql备份脚本 zabbix错误日志 直接送给bc做计算 gzip innobackupex/Xtrabackup 第四十节课
- 阿里云 CentOS 7安装MySQL
- Cordys对浏览器支持信息(Support information on latest browsers)
- 暴力匹配---Longest Common Substring
- 【Android】【笔记】《Android 入门经典》part 2 安卓的基本组件
- CentOS命令buffer和cache 的区别
- VS开发C语言系列(零)-VS2013写C语言错误汇总
- jQuery插件Validation学习(二)——rules的使用
- 【Android】【笔记】《Android 入门经典》part 1 安卓程序的组成
- 回顾二分法排序
- Linq学习(五)-多表连接
- 关注两篇gatekeeper的论坛
- Internet Explorer 9、10、11兼容性分析处理经验谈
- java实现多线程内存可见性
- hdu 5615 Jam's math problem(十字相乘判定)
- 早教管理系统浅谈
- LeetCode Valid Anagram Hashtable
- hdoj5616Jam's balance【dp】