9北京抑郁症医院是私人的吗,but I youllneverwalkalone walk backwards 9

CC++(10)
转化过程非常简单,就是整数部分对进制辗转取于,小数部分乘以进制,大于整数进位否则取0;
如12.56,小数部分转化为二进制:
0.56*2 = 1.12 &取 1
0.12*2 = 0.24 取 0
0.24*2 = .48 取 0
0.48*2 = 0.96 取 0
0.96*2 = 1.92 取 1
……依次类推、、、
#include &stdio.h&
#include &string.h&
void two(int x, float y)
int a[1000], b[1000];
int t = 5;
int i = 0, j = 0;
a[i++] = x%2;
while(t--)
float p = 2.0*y;
if(p &= 1)
b[j++] = 1;
b[j++] = 0;
for(int k = i-1; k &= 0; k--)
printf(&%d&,a[k]);
printf(&.&);
for(int k = 0; k & k++)
printf(&%d&,b[k]);
printf(&\n&);
void eight(int x, float y)
int a[120], b[120], i = 0, j = 0;
int t = 5;
a[i++] = x%8;
while(t--)
float p = 8*y;
int xx = (int)p;
if(xx &= 1)
b[j++] = 0;
for(int k = i-1; k &= 0; k--)
printf(&%d&,a[k]);
printf(&.&);
for(int k = 0; k & k++)
printf(&%d&,b[k]);
printf(&\n&);
void sixteen(int x, float y)
int i = 0, j = 0, t = 5;
char a[120], b[120];
int p = x%16;
if(p == 10)
a[i++] = 'A';
else if(p == 11)
a[i++] = 'B';
else if(p == 12)
a[i++] = 'C';
else if(p == 13)
a[i++] = 'D';
else if(p == 14)
a[i++] = 'E';
else if(p == 15)
a[i++] = 'F';
a[i++] = p+'0';
while(t--)
float yy = 16*y;
float pp =
int xx = (int)
if(xx &= 10)
b[j++] = 'A'+xx-10;
else if(xx &= 1)
b[j++] = xx+'0';
for(int k = i-1; k &= 0; k--)
printf(&%c&,a[k]);
printf(&.&);
for(int k = 0; k & k++)
printf(&%c&,b[k]);
printf(&\n&);
int main()//进制转换,每次只取小数点后五位
float x, y,
while(~scanf(&%f&,&z))
t = (int)z;
y);//二进制转化
y);//八进制转化
sixteen(t,
y);//十六进制转换
参考知识库
* 以上用户言论只代表其个人观点,不代表CSDN网站的观点或立场
访问:405054次
积分:8139
积分:8139
排名:第1644名
原创:418篇
转载:20篇
评论:50条
比自己厉害百倍的人都在加倍努力,每天又有什么理由偷懒?
文章:46篇
阅读:24300
http://www.xufulong.net/
(2)(2)(5)(31)(4)(19)(14)(5)(34)(35)(21)(15)(20)(16)(51)(1)(10)(18)(14)(21)(59)(7)(7)(3)(5)(9)(7)(3)URAL(17)
水题(41)
题目不太好读懂,就是先给你一个n代表要从n个物品中买东西,然后告诉你这n个东西的单价,在给你m个集合的情况,就是每个结合中有x件物品,他们合起来买的价格是k。这x件物品依次是:p1……px。之后给你一个kk,表示你要买的物品的编号。让你求出来如何花费最少的钱买到要求的序列。
20,可以状压啊,注意一开始的时候先把单价的状态处理出来。。。之后就是水题了啊。
1326. Bottle Taps
Time limit: 3.0 second
Memory limit: 64 MB
Programmer Petrov has a hobby to collect beer-bottle taps. There’s nothing unusual — he knows hundreds of programmers that like beer. And they collect taps, too. Not everyone, but some of them.
Frankly speaking, he has bought a part of his collection. But unfortunately he hasn’t got some rare taps to complete his collection. He has found some programmers over the Internet that are ready to
sell him these taps. Some of the programmers sell the taps in sets with big discounts.
It’s left to find an optimal offer. Petrov can explain to his wife why he is to store the taps but he won’t be able to prove why he is to spend money for the collection. So he is to buy the taps as
cheap as possible.
Petrov has written down all the variants and has started thinking. There’s no way to find out the solution of the problem without a program!
The first line contains an integer&N, an amount of available taps&(1 ≤&N&≤ 20). The following&Nlines contain prices of bottles with the taps if one buys them
in stores. The next line contains an integer&M&(0 ≤&M&≤ 100)&— an amount of offers to sell the taps. The following&M&lines describe the sets. The first number of each line is the price of the set and the second one is
the amount of taps in the set. Then there are numbers of the taps in the set (each number lies in the range from 1 to&N). The numbers in a set are unique. All the prices are positive integers and do not exceed 1000. The last line begins with the amount
of taps that Petrov plans to buy. Then their numbers follow separated by spaces. These numbers are unique, too.
Output the minimal sum of money that Petrov should spend on obtaining the necessary taps.
25 3 2 3 4
#include &algorithm&
#include &iostream&
#include &stdlib.h&
#include &string.h&
#include &iomanip&
#include &stdio.h&
#include &string&
#include &queue&
#include &cmath&
#include &stack&
#include &map&
#include &set&
#define eps 1e-8
#define M 1000100
#define LL __int64
//#define LL long long
#define INF 0x3f3f3f
#define PI 3.8
const int maxn = 1010;
int dp[1&&22];
int num[maxn];
int f[maxn];
int st[maxn];
void dfs(int x, int y, int z)
if(x == n)
dfs(x+1, y, z);
dfs(x+1, y|(1&&x), z+num[x]);
int main()
while(~scanf(&%d&,&n))
for(int i = 0; i & (1&&n); i++) dp[i] = INF;
for(int i = 0; i & i++) scanf(&%d&,&num[i]);
dfs(0, 0, 0);
scanf(&%d&,&m);
= 0; i & i++)
scanf(&%d&,&f[i]);
scanf(&%d&,&x);
int sum = 0;
for(int j = 0; j & j++)
scanf(&%d&,&tmx);
sum |= (1&&(tmx-1));
scanf(&%d&,&kk);
int ans = 0;
for(int i = 0; i & i++)
scanf(&%d&, &p);
ans |= (1&&(p-1));
int Min = INF;
for(int i = 0; i & (1&&n); i++)
if((i&ans) == ans) Min = min(Min, dp[i]);
for(int j = 0; j & j++) dp[i|st[j]] = min(dp[i|st[j]], dp[i]+f[j]);
printf(&%d\n&,Min);
参考知识库
* 以上用户言论只代表其个人观点,不代表CSDN网站的观点或立场
访问:405056次
积分:8139
积分:8139
排名:第1644名
原创:418篇
转载:20篇
评论:50条
比自己厉害百倍的人都在加倍努力,每天又有什么理由偷懒?
文章:46篇
阅读:24300
http://www.xufulong.net/
(2)(2)(5)(31)(4)(19)(14)(5)(34)(35)(21)(15)(20)(16)(51)(1)(10)(18)(14)(21)(59)(7)(7)(3)(5)(9)(7)(3)数据结构(37)
学习笔记(20)
需要温故(17)
RMQ(Range Minimum/Maximum Query),即区间最值查询,是指这样一个问题:对于长度为n的数列A,回答若干询问RMQ(A,i,j)(i,j&=n),返回数列A中下标在i,j之间的最小/大值。这两个问题是在实际应用中经常遇到的问题,下面介绍一下解决这两种问题的比较高效的算法。当然,该问题也可以用线段树(也叫区间树)解决,算法复杂度为:O(N)~O(logN),这里我们暂不介绍。
对于该问题,最容易想到的解决方案是遍历,复杂度是O(n)。但当数据量非常大且查询很频繁时,该算法无法在有效的时间内查询出正解。
本节介绍了一种比较高效的在线算法(ST算法)解决这个问题。所谓在线算法,是指用户每输入一个查询便马上处理一个查询。该算法一般用较长的时间做预处理,待信息充足以后便可以用较少的时间回答每个查询。ST(Sparse Table)算法是一个非常有名的在线处理RMQ问题的算法,它可以在O(nlogn)时间内进行预处理,然后在O(1)时间内回答每个查询。
(一)首先是预处理,用动态规划(DP)解决。
设A[i]是要求区间最值的数列,F[i, j]表示从第i个数起连续2^j个数中的最大值。(DP的状态)
A数列为:3 2 4 5 6 8 1 2 9 7
F[1,0]表示第1个数起,长度为2^0=1的最大值,其实就是3这个数。同理 F[1,1] = max(3,2) = 3, F[1,2]=max(3,2,4,5) = 5,F[1,3] = max(3,2,4,5,6,8,1,2) = 8;
并且我们可以容易的看出F[i,0]就等于A[i]。(DP的初始值)
这样,DP的状态、初值都已经有了,剩下的就是状态转移方程。
我们把F[i,j]平均分成两段(因为f[i,j]一定是偶数个数字),从 i 到i + 2 ^ (j - 1) - 1为一段,i + 2 ^ (j - 1)到i + 2 ^ j - 1为一段(长度都为2 ^ (j - 1))。用上例说明,当i=1,j=3时就是3,2,4,5 和 6,8,1,2这两段。F[i,j]就是这两段各自最大值中的最大值。于是我们得到了状态转移方程F[i, j]=max(F[i,j-1], F[i + 2^(j-1),j-1])。
代码如下:
void RMQ(int num) //预处理-&O(nlogn)
for(int j = 1; j & 20; ++j)
for(int i = 1; i &= ++i)
if(i + (1 && j) - 1 &= num)
maxsum[i][j] = max(maxsum[i][j - 1], maxsum[i + (1 && (j - 1))][j - 1]);
minsum[i][j] = min(minsum[i][j - 1], minsum[i + (1 && (j - 1))][j - 1]);
这里我们需要注意的是循环的顺序,我们发现外层是j,内层所i,这是为什么呢?可以是i在外,j在内吗?
答案是不可以。因为我们需要理解这个状态转移方程的意义。
状态转移方程的含义是:先更新所有长度为F[i,0]即1个元素,然后通过2个1个元素的最值,获得所有长度为F[i,1]即2个元素的最值,然后再通过2个2个元素的最值,获得所有长度为F[i,2]即4个元素的最值,以此类推更新所有长度的最值。
而如果是i在外,j在内的话,我们更新的顺序就是F[1,0],F[1,1],F[1,2],F[1,3],表示更新从1开始1个元素,2个元素,4个元素,8个元素(A[0],A[1],....A[7])的最值,这里F[1,3] = max(max(A[0],A[1],A[2],A[3]),max(A[4],A[5],A[6],A[7]))的值,但是我们根本没有计算max(A[0],A[1],A[2],A[3])和max(A[4],A[5],A[6],A[7]),所以这样的方法肯定是错误的。
为了避免这样的错误,一定要好好理解这个状态转移方程所代表的含义。
(二)然后是查询。
假如我们需要查询的区间为(i,j),那么我们需要找到覆盖这个闭区间(左边界取i,右边界取j)的最小幂(可以重复,比如查询5,6,7,8,9,我们可以查询)。
因为这个区间的长度为j - i + 1,所以我们可以取k=log2( j - i + 1),则有:RMQ(A, i, j)=max{F[i , k], F[ j - 2 ^ k + 1, k]}。
举例说明,要求区间[2,8]的最大值,k = log2(8 - 2 + 1)= 2,即求max(F[2, 2],F[8 - 2 ^ 2 + 1, 2]) = max(F[2, 2],F[5, 2]);
在这里我们也需要注意一个地方,就是&&运算符和+-运算符的优先级。
比如这个表达式:5 - 1 && 2是多少?
答案是:4 * 2 * 2 = 16。所以我们要写成5 - (1 && 2)才是5-1 * 2 * 2 = 1。
查询的代码是:
while(1&&(k+1) &= r-l+1)
Max = max(Dp_Max[l][k], Dp_Max[r-(1&&k)+1][k]);
Min = min(Dp_Min[l][k], Dp_Min[r-(1&&k)+1][k]);
参考知识库
* 以上用户言论只代表其个人观点,不代表CSDN网站的观点或立场
访问:405058次
积分:8139
积分:8139
排名:第1644名
原创:418篇
转载:20篇
评论:50条
比自己厉害百倍的人都在加倍努力,每天又有什么理由偷懒?
文章:46篇
阅读:24300
http://www.xufulong.net/HDU刷题(129)
AC自动模版题,中文题目就不叙述题意了啊。
AC自动主要是构造出字典树之后找到fail指针的跳转,类似于KMP里面的next数组的跳转啊,注意这里是多模式跳转。意思就是这个串跳到下一个串的什么位置啊。
先帖一下,做多了再一起总结吧。
Problem Description
Sample Input
Sample Output
#include &algorithm&
#include &iostream&
#include &stdlib.h&
#include &string.h&
#include &iomanip&
#include &stdio.h&
#include &string&
#include &queue&
#include &cmath&
#include &stack&
#include &map&
#include &set&
#define eps 1e-12
///#define M 1000100
#define LL __int64
///#define LL long long
///#define INF 0x7ffffff
#define INF 0x3f3f3f3f
#define PI 3.8
#define zero(x) ((fabs(x)&eps)?0:x)
const int maxn = 1000010;
struct node
int next[130], fail,
} f[maxn];
bool vis[510];
char s[1000010];
inline int Sel(char s)
return s-' ';
int creat()
memset(f[Top].next, -1, sizeof(f[Top].next));
f[Top].fail = -1;
f[Top].flag = 0;
return Top++;
void Get_tree(char *s, int root, int site, int x)
while(s[site] != '\0')
if(f[root].next[Sel(s[site])] == -1) f[root].next[Sel(s[site])] = creat();
root = f[root].next[Sel(s[site])];
f[root].flag =
int Get_fail(int site, int x)
if(site == -1) return 0;
if(f[site].next[x] != -1) return f[site].next[x];
site = f[site].
queue&int&q;
void Get_fail(int root)
f[root].fail = -1;
while(!q.empty()) q.pop();
q.push(root);
while(!q.empty())
x = q.front();
for(int i = 0; i &= 128; i++)
if(f[x].next[i] != -1)
f[f[x].next[i]].fail = Get_fail(f[x].fail, i);
q.push(f[x].next[i]);
int Match(char *s, int root, int site)
int ans = 0;
for(site = 1; s[site] != '\0'; site++)
while(p != -1 && f[p].next[Sel(s[site])] == -1) p = f[p].
if(p == -1)
p = f[p].next[Sel(s[site])];
while(tmp != root && f[tmp].flag != -1)
if(f[tmp].flag)
vis[f[tmp].flag] = 1;
tmp = f[tmp].
int main()
while(~scanf(&%d&,&n))
int root = creat();
for(int i = 1; i &= i++)
scanf(&%s&, s+1);
Get_tree(s, root, 1, i);
Get_fail(root);
scanf(&%d&,&m);
int total = 0;
for(int i = 0; i & i++)
memset(vis, 0, sizeof(vis));
scanf(&%s&,s+1);
ans = Match(s, root, 1);
printf(&web %d:&, i+1);
for(int j = 1; j &= j++)
if(vis[j]) printf(& %d&,j);
printf(&total: %d\n&,total);
参考知识库
* 以上用户言论只代表其个人观点,不代表CSDN网站的观点或立场
访问:405060次
积分:8139
积分:8139
排名:第1644名
原创:418篇
转载:20篇
评论:50条
比自己厉害百倍的人都在加倍努力,每天又有什么理由偷懒?
文章:46篇
阅读:24300
http://www.xufulong.net/
(2)(2)(5)(31)(4)(19)(14)(5)(34)(35)(21)(15)(20)(16)(51)(1)(10)(18)(14)(21)(59)(7)(7)(3)(5)(9)(7)(3)

我要回帖

更多关于 never walk backwards 的文章

 

随机推荐