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的更多相关文章
随机推荐
- PHP设计模式(二)
从最近开始我给自己定了个目标,每周至少更新2篇博客,用来记录自己在上一周里面遇到的问题或者想出的新点子,一方面对自己掌握的知识进行记录,免得时间久了忘得一干二净,二来我的博文虽然不怎么好但也许会对一小 ...
- Centos下 为Firefox安装Flash插件
方法一: 直接到官网去下载RPM格式的安装包,下载好后直接 用 rpm -ivh XXXX.rpm 来安装即可. 方法二: 到官网下载tar.gz格式的,自己配置安装: #wget http://fp ...
- jQuery ajax - serialize() 方法-输出序列化表单值
定义和用法 serialize() 方法通过序列化表单值,创建 URL 编码文本字符串. 您可以选择一个或多个表单元素(比如 input 及/或 文本框),或者 form 元素本身. 序列化的值可在生 ...
- 【Alpha版本】冲刺-Day6
队伍:606notconnected 会议时间:11月14日 会议总结 张斯巍(433) 今天安排:学习UI设计 完成度:100% 明天计划:上传界面设计 遇到的问题:无 感想:刚开始学的时候,都是从 ...
- JQuery 学习笔记(01)
JQuery是继prototype之后又一个优秀的Javascript库.它是轻量级的js库 ,它兼容CSS3,还兼容各种浏览器(IE 6.0+, FF 1.5+, Safari 2.0+, Oper ...
- 安装和使用Linux花生壳(公网版)
一.安装说明 1.下载相应的安装包,安装程序 2.运行程序.配置程序(默认使用/etc/phlinux.conf,如果不存在这个文件则自动进入交互配置) [root@localhost -]# phd ...
- href和src的使用场景
href和src的使用场景 href和src的用法虽然简单,但是有时候会突然记不起来该怎么用,且两者不可相互替换,下面列出来方便记忆,并给出具体区别. href的使用: 1.外部css引用:<l ...
- 关于vs生成app错误提示,提醒Execution failed for task ':transformClassesWithDexForDebug'.
昨天将vs和android SDK更新之后生成app之后发现app生成出错,报错如下: FAILURE: Build failed with an exception. * What went wro ...
- netty 解决TCP粘包与拆包问题(一)
1.什么是TCP粘包与拆包 首先TCP是一个"流"协议,犹如河中水一样连成一片,没有严格的分界线.当我们在发送数据的时候就会出现多发送与少发送问题,也就是TCP粘包与拆包.得不到我 ...
- C#--API
C#中调用API 介绍 API( Application Programming Interface ),我想大家不会陌生,它是我们Windows编程的常客,虽然基于.Net平台的C#有了强大的类库, ...