LUXURY15
Time Limit:1000MS Memory Limit:262144KB 64bit IO Format:%I64d & %I64u
Description
Amr bought a new video game "Guess Your Way Out!". The goal of the game is to find an exit from the maze that looks like a perfect binary tree of height h. The player is initially standing at the root of the tree and the exit from the tree is located at some leaf node.
Let's index all the leaf nodes from the left to the right from 1 to 2h. The exit is located at some node n where 1 ≤ n ≤ 2h, the player doesn't know where the exit is so he has to guess his way out!
Amr follows simple algorithm to choose the path. Let's consider infinite command string "LRLRLRLRL..." (consisting of alternating characters 'L' and 'R'). Amr sequentially executes the characters of the string using following rules:
- Character 'L' means "go to the left child of the current node";
- Character 'R' means "go to the right child of the current node";
- If the destination node is already visited, Amr skips current command, otherwise he moves to the destination node;
- If Amr skipped two consecutive commands, he goes back to the parent of the current node before executing next command;
- If he reached a leaf node that is not the exit, he returns to the parent of the current node;
- If he reaches an exit, the game is finished.
Now Amr wonders, if he follows this algorithm, how many nodes he is going to visit before reaching the exit?
Input
Input consists of two integers h, n (1 ≤ h ≤ 50, 1 ≤ n ≤ 2h).
Output
Output a single integer representing the number of nodes (excluding the exit node) Amr is going to visit before reaching the exit by following this algorithm.
Sample Input
1 2
2
2 3
5
3 6
10
10 1024
2046
这道题厉害(把今天做比赛的小牛全部吓跑了||-_-),实际上就是道数学题。
首先把当前他给的出口转换为完全二叉树上的叶子节点标号exit,然后你就可以O(50)的复杂度内求出exit的所有祖先ans[] ;
然后你可以设path[],表示当前这个点是他父亲的左儿子(0),还是右儿子(1)。
通过观察你可以得到这个结论,如果path[i] != path[i-1] ,那么你就把i-1的另一个儿子产生的那颗子树上的节点全部加上,
反之的话这次只要加以。
#include<bits/stdc++.h>
using namespace std;
typedef long long ll ;
ll ans[] ;
bool path[] ;
ll h , n ;
ll tot ; void solve () {
//cout << "n = " << n << endl ;
//cout << "h = " << h << endl ;
ans[h] = n ;
for (int i = h - ; i >= ; i --) ans[i] = ans[i+]/ ;
if (ans[] == ) path[] = , tot += ;
else path[] = , tot += (1ll<<(h-)) + ;
//printf ("ans[2] = %I64d , path[2] = %d\n" , ans[2] , path[2]) ;
//cout << tot << endl ;
for (int i = ; i <= h ; i ++) {
if (ans[i-] * + == ans[i]) path[i] = ;
else path[i] = ;
tot ++ ;
if (path[i] == path[i-]) tot += (1ll<<(h-i+)) - ;
//printf ("ans = %I64d , path[%d] = %d\n" , ans[i] , i , path[i]) ;
//cout << tot << endl ;
}
cout << tot - << endl ;
} int main () {
cin >> h >> n ;
if (h == && n == ) {
cout << << endl ;
return ;
}
n += (1ll<<h) - ;
h ++ ;
solve () ;
return ;
}
Time Limit:2000MS Memory Limit:262144KB 64bit IO Format:%I64d & %I64u
Description
Andrewid the Android is a galaxy-famous detective. He is now investigating the case of vandalism at the exhibition of contemporary art.
The main exhibit is a construction of n matryoshka dolls that can be nested one into another. The matryoshka dolls are numbered from 1to n. A matryoshka with a smaller number can be nested in a matryoshka with a higher number, two matryoshkas can not be directly nested in the same doll, but there may be chain nestings, for example, 1 → 2 → 4 → 5.
In one second, you can perform one of the two following operations:
- Having a matryoshka a that isn't nested in any other matryoshka and a matryoshka b, such that b doesn't contain any other matryoshka and is not nested in any other matryoshka, you may put a in b;
- Having a matryoshka a directly contained in matryoshka b, such that b is not nested in any other matryoshka, you may get a out ofb.
According to the modern aesthetic norms the matryoshka dolls on display were assembled in a specific configuration, i.e. as several separate chains of nested matryoshkas, but the criminal, following the mysterious plan, took out all the dolls and assembled them into a single large chain (1 → 2 → ... → n). In order to continue the investigation Andrewid needs to know in what minimum time it is possible to perform this action.
Input
The first line contains integers n (1 ≤ n ≤ 105) and k (1 ≤ k ≤ 105) — the number of matryoshkas and matryoshka chains in the initial configuration.
The next k lines contain the descriptions of the chains: the i-th line first contains number mi (1 ≤ mi ≤ n), and then mi numbersai1, ai2, ..., aimi — the numbers of matryoshkas in the chain (matryoshka ai1 is nested into matryoshka ai2, that is nested into matryoshka ai3, and so on till the matryoshka aimi that isn't nested into any other matryoshka).
It is guaranteed that m1 + m2 + ... + mk = n, the numbers of matryoshkas in all the chains are distinct, in each chain the numbers of matryoshkas follow in the ascending order.
Output
In the single line print the minimum number of seconds needed to assemble one large chain from the initial configuration.
Sample Input
3 2
2 1 2
1 3
1
7 3
3 1 3 7
2 2 5
2 4 6
10
这道题乱入进来的,就是个模拟。
#include<bits/stdc++.h>
using namespace std;
typedef long long ll ;
const int M = 1e5 + ;
int n , k ;
ll tot ;
ll len ;
int path[M] ;
ll cnt ; int main () {
ios::sync_with_stdio (false) ;
cin >> n >> k ;
tot = n- - (k-) ;
for (int i = ; i < k ; i ++) {
int num ;
cin >> num ;
for (int i = ; i < num ; i ++) cin >> path[i] ;
if (path[] = ) {
for (int i = ; i < num ; i ++) {
if (path[i] == path[i-] + ) cnt ++ ;
else break ;
}
}
}
tot -= cnt ;
tot += n - - cnt ;
cout << tot << endl ;
return ;
}
Time Limit:1000MS Memory Limit:262144KB 64bit IO Format:%I64d & %I64u
Description
Arthur has bought a beautiful big table into his new flat. When he came home, Arthur noticed that the new table is unstable.
In total the table Arthur bought has n legs, the length of the i-th leg is li.
Arthur decided to make the table stable and remove some legs. For each of them Arthur determined number di — the amount of energy that he spends to remove the i-th leg.
A table with k legs is assumed to be stable if there are more than half legs of the maximum length. For example, to make a table with 5legs stable, you need to make sure it has at least three (out of these five) legs of the maximum length. Also, a table with one leg is always stable and a table with two legs is stable if and only if they have the same lengths.
Your task is to help Arthur and count the minimum number of energy units Arthur should spend on making the table stable.
Input
The first line of the input contains integer n (1 ≤ n ≤ 105) — the initial number of legs in the table Arthur bought.
The second line of the input contains a sequence of n integers li (1 ≤ li ≤ 105), where li is equal to the length of the i-th leg of the table.
The third line of the input contains a sequence of n integers di (1 ≤ di ≤ 200), where di is the number of energy units that Arthur spends on removing the i-th leg off the table.
Output
Print a single integer — the minimum number of energy units that Arthur needs to spend in order to make the table stable.
Sample Input
2
1 5
3 2
2
3
2 4 4
1 1 1
0
6
2 2 1 1 3 3
4 3 5 5 2 1
8
暴力枚举1~1e5 ,使他们分别为最大桌腿时的需要消耗的能量,不断取最小。
一大堆前缀和,后缀和混在一起。。。
#include<bits/stdc++.h>
using namespace std;
const int M = 1e5 + , inf = 0x3f3f3f3f ;
int vis[M] ;
int engry[M] ;
struct node {
int all ;
int num[M] ;
} a[] ;
int n ;
int len[M] ;
pair<int,int> ure[M] ; void solve () {
int minn = inf ;
for (int i = ; i <= M - ; i ++) {
if (vis[i] == ) continue ;
int tmp = ure[i+].second ;
int cut = n - ure[i+].first - (*vis[i]-) ;
if (cut <= ) {
minn = min (minn , tmp) ;
continue ;
}
int cnt = ;
for (int j = ; j <= ; j ++) {
int dif = cut - cnt ;
if (dif <= a[j].num[i-]) {
tmp += j * dif ;
break ;
}
tmp += j * a[j].num[i-];
cnt += a[j].num[i-] ;
}
minn = min (minn , tmp) ;
}
cout << minn << endl ;
} int main () {
ios::sync_with_stdio (false) ;
cin >> n ;
for (int i = ; i < n ; i ++) {
cin >> len[i] ;
vis[len[i]] ++ ;
}
for (int i = ; i < n ; i ++) {
int x ;
cin >> x ;
a[x].all ++ ;
a[x].num[len[i]] ++ ;
engry[len[i]] += x ;
}
for (int i = M - ; i >= ; i --) ure[i].first += vis[i] + ure[i+].first , ure[i].second += engry[i] + ure[i+].second ;
for (int i = ; i <= ; i ++) {
for (int j = ; j <= M - ; j ++) a[i].num[j] += a[i].num[j-] ;
}
solve () ;
return ;
}
Time Limit:1000MS Memory Limit:262144KB 64bit IO Format:%I64d & %I64u
Description
The first algorithm for detecting a face on the image working in realtime was developed by Paul Viola and Michael Jones in 2001. A part of the algorithm is a procedure that computes Haar features. As part of this task, we consider a simplified model of this concept.
Let's consider a rectangular image that is represented with a table of size n × m. The table elements are integers that specify the brightness of each pixel in the image.
A feature also is a rectangular table of size n × m. Each cell of a feature is painted black or white.
To calculate the value of the given feature at the given image, you must perform the following steps. First the table of the feature is put over the table of the image (without rotations or reflections), thus each pixel is entirely covered with either black or white cell. The valueof a feature in the image is the value of W - B, where W is the total brightness of the pixels in the image, covered with white feature cells, and B is the total brightness of the pixels covered with black feature cells.
Some examples of the most popular Haar features are given below.
Your task is to determine the number of operations that are required to calculate the feature by using the so-called prefix rectangles.
A prefix rectangle is any rectangle on the image, the upper left corner of which coincides with the upper left corner of the image.
You have a variable value, whose value is initially zero. In one operation you can count the sum of pixel values at any prefix rectangle, multiply it by any integer and add to variable value.
You are given a feature. It is necessary to calculate the minimum number of operations required to calculate the values of this attribute at an arbitrary image. For a better understanding of the statement, read the explanation of the first sample.
Input
The first line contains two space-separated integers n and m (1 ≤ n, m ≤ 100) — the number of rows and columns in the feature.
Next n lines contain the description of the feature. Each line consists of m characters, the j-th character of the i-th line equals to "W", if this element of the feature is white and "B" if it is black.
Output
Print a single number — the minimum number of operations that you need to make to calculate the value of the feature.
Sample Input
6 8
BBBBBBBB
BBBBBBBB
BBBBBBBB
WWWWWWWW
WWWWWWWW
WWWWWWWW
2
3 3
WBW
BWW
WWW
4
3 6
WWBBWW
WWBBWW
WWBBWW
3
4 4
BBBB
BBBB
BBBB
BBBW
4
Hint
The first sample corresponds to feature B, the one shown in the picture. The value of this feature in an image of size 6 × 8 equals to the difference of the total brightness of the pixels in the lower and upper half of the image. To calculate its value, perform the following twooperations:
- add the sum of pixels in the prefix rectangle with the lower right corner in the 6-th row and 8-th column with coefficient 1 to the variable value (the rectangle is indicated by a red frame);
- add the number of pixels in the prefix rectangle with the lower right corner in the 3-rd row and 8-th column with coefficient - 2and variable value.
Thus, all the pixels in the lower three rows of the image will be included with factor 1, and all pixels in the upper three rows of the image will be included with factor 1 - 2 = - 1, as required.
这道题很神,题目读起来特费劲。简单来说是这样,一个图里有W,B这两种颜色,你可以每次进行一种操作:从左上角拉出一个矩阵来(你可以想象鼠标在那里右击一下然后拉出了一个矩阵),在那个矩阵里
所有数字都加上一个任意大小的整数。进过这样若干次操作后,最终是w变成1,b变成-1.
问你最少的操作次数。
题解的思路真心好。首先你肯定会得出这么一个结论,一定要从矩阵最外围那里进行修改。
然后做法是这样,首先把这幅图上的W变成1 , B变成-1,那么我们现在要做的就是怎么用最少的操作次数把现在的这张图变成一开始都是0的图了。
#include<bits/stdc++.h>
using namespace std;
int mp[][] ;
int n , m ; int main () {
ios::sync_with_stdio (false) ;
cin >> n >> m ;
for (int i = ; i <= n ; i ++) {
for (int j = ; j <= m ; j ++) {
char x ;
cin >> x ;
mp[i][j] = x == 'B' ? : - ;
}
} int cnt = ;
for (int i = n ; i >= ; i --) {
for (int j = m ; j >= ; j --) {
if (mp[i][j] == ) continue ;
cnt ++ ;
int tmp = mp[i][j] ;
for (int k = i ; k >= ; k --) {
for (int t = j ; t >= ; t --) {
mp[k][t] -= tmp ;
}
}
}
}
cout << cnt << endl ;
return ;
}
Time Limit:2000MS Memory Limit:262144KB 64bit IO Format:%I64d & %I64u
Description
Kyoya Ootori has a bag with n colored balls that are colored with k different colors. The colors are labeled from 1 to k. Balls of the same color are indistinguishable. He draws balls from the bag one by one until the bag is empty. He noticed that he drew the last ball of color i before drawing the last ball of color i + 1 for all i from 1 to k - 1. Now he wonders how many different ways this can happen.
Input
The first line of input will have one integer k (1 ≤ k ≤ 1000) the number of colors.
Then, k lines will follow. The i-th line will contain ci, the number of balls of the i-th color (1 ≤ ci ≤ 1000).
The total number of balls doesn't exceed 1000.
Output
A single integer, the number of ways that Kyoya can draw the balls from the bag as described in the statement, modulo 1 000 000 007.
Sample Input
3
2
2
1
3
4
1
2
3
4
1680
Hint
In the first sample, we have 2 balls of color 1, 2 balls of color 2, and 1 ball of color 3. The three ways for Kyoya are:
1 2 1 2 3
1 1 2 2 3
2 1 1 2 3
虽然一开始就知道是dp,但我没有正确的确定当前的要转移的状态是什么。
题解里说dp[i],表示只用前i种颜色的所有组合情况,那就很明显了,dp[i] = dp[i-1]*C(c[i]-1,pre[i]-1) ;
用了组合数学的姿势,第一次写这种玩意,借鉴了一下大牛的打表姿势。
#include<bits/stdc++.h>
using namespace std;
typedef long long ll ;
const ll mod = 1e9 + ;
int k ;
int a[] ;
ll f[] ;
ll pre[] ;
ll c[][] ; int main () {
ios::sync_with_stdio (false) ;
cin >> k ;
for (int i = ; i <= k ; i ++) {
cin >> a[i] ;
pre[i] += pre[i-] + a[i] ;
}
for (int i = ; i <= ; i ++) {
c[i][] = ;
for (int j = ; j <= i ; j ++) c[i][j] = (c[i-][j] + c[i-][j-]) % mod ;
}
f[] = ;
for (int i = ; i <= k ; i ++) {
f[i] = f[i-]*c[pre[i]-][a[i]-] % mod ;
//printf ("(%I64d , %d)\n" , pre[i]-1 , a[i]-1) ;
//cout << "f[" << i << "] = " << f[i] << endl ;
}
cout << f[k] << endl ;
return ;
}
LUXURY15的更多相关文章
随机推荐
- 加州大学伯克利分校Stat2.2x Probability 概率初步学习笔记: Section 4 The Central Limit Theorem
Stat2.2x Probability(概率)课程由加州大学伯克利分校(University of California, Berkeley)于2014年在edX平台讲授. PDF笔记下载(Acad ...
- Python核心编程第三版第二章学习笔记
第二章 网络编程 1.学习笔记 2.课后习题 答案是按照自己理解和查阅资料来的,不保证正确性.如由错误欢迎指出,谢谢 1. 套接字:A network socket is an endpoint of ...
- JavaScript Ajax之美~
JavaScript Ajax之美~ 曾经有一段时期,因为开发人员对JavaScript的滥用导致其遭受了一段时间的冷门时期,不被大家看好,后来,到了2005年,Google公司的很多技术都是用了aj ...
- 菜鸟之linux问题之图形界面和dos界面的登录问题
1.安装完linux系统后,图形化界面的用户名和密码是之前安装的时候设置的. 如果想切换到linux的dos窗口快捷键是:ctrl+alt+F2 由dos窗口切换到linux图形界面快捷键是:ctrl ...
- java8 中的时间和数据的变化
java8除了lambda表达式之外还对时间和数组这两块常用API做想应调整, Stream 有几个常用函数: store 排序 (a,b)-> a.compareTo(b) 排出来的结果是正 ...
- SQL 字段保留下划线后部分
select SUBSTRING(b.SUMMARY,0,charindex('_',b.SUMMARY))as SUMMARY from UltimusDB.dbo.INCIDENTS b
- split shell tools
split [-bl] file [prefix] 参数说明: -b, --bytes=SIZE:对file进行切分,每个小文件大小为SIZE.可以指定单位b,k,m. -l, --lines=NUM ...
- Ad-Hoc命令不熟悉的选项
-f #并发线程数,默认5个线程 --private-key #指定秘钥文件 -k #--ask-pass SSH:认证密码 -K, #--ask-sudo-pass sudo:用户的密码(--sud ...
- LyX-220-Installer-3
所见即所得 单独安装这个写作业可以了,要发论文用CTeX Ctrl + M 打开数学输入,里面可以输入 TeX 代码
- 解惑好文:移动端H5页面高清多屏适配方案 (转)
转自:http://mobile.51cto.com/web-484304.htm https://github.com/amfe/lib-flexible/blob/master/src/makeg ...