如果可以,可以陪你千年不老,千年只想眷顾你倾城一笑;如果愿意,愿意陪你永世不离,永世只愿留恋你青丝白衣。

Asteroids

Bessie wants to navigate her spaceship through a dangerous asteroid field in the shape of an N x N grid (1 <= N <= 500). The grid contains K asteroids (1 <= K <= 10,000), which are conveniently located at the lattice points of the grid.

Fortunately, Bessie has a powerful weapon that can vaporize all the asteroids in any given row or column of the grid with a single shot.This weapon is quite expensive, so she wishes to use it sparingly.Given the location of all the asteroids in the field, find the minimum number of shots Bessie needs to fire to eliminate all of the asteroids.

Input

* Line 1: Two integers N and K, separated by a single space. 
* Lines 2..K+1: Each line contains two space-separated integers R and C (1 <= R, C <= N) denoting the row and column coordinates of an asteroid, respectively.

Output

* Line 1: The integer representing the minimum number of times Bessie must shoot.

Sample Input

3 4
1 1
1 3
2 2
3 2

Sample Output

2

Hint

INPUT DETAILS: 
The following diagram represents the data, where "X" is an asteroid and "." is empty space: 
X.X 
.X. 
.X.

OUTPUT DETAILS: 
Bessie may fire across row 1 to destroy the asteroids at (1,1) and (1,3), and then she may fire down column 2 to destroy the asteroids at (2,2) and (3,2).

#include <iostream>
#include <cstdio>
#include <algorithm>
#include <string>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <vector>
#include <ctime>
#include <cctype>
#include <bitset>
#include <utility>
#include <sstream>
#include <complex>
#include <iomanip>
#define inf 0x3f3f3f3f
typedef long long ll;
using namespace std;
int N,K,x,y;
int line[10010][10010],used[10010],nx[10010];
//used[i]表示某次访问i这个女生是否匹配,nx[i]表示i女生匹配的男生
bool Find(int x)//x表示第x个男生
{for(int i=1; i<=N; i++){if(line[x][i]==1&&!used[i]){used[i]=1;if(nx[i]==-1||Find(nx[i]))//如果这个女生没有匹配的男生或者这个匹配的男生是可以腾位置的{nx[i]=x;//这个女生就和这个男生匹配return true;}}}return false;
}
int match()
{int sum=0;for(int i=1; i<=N; i++)//给每个男生匹配{memset(used,0,sizeof(used));if(Find(i))sum++;}return sum;
}
int main()
{cin>>N>>K;memset(nx,-1,sizeof(nx));while(K--){cin>>x>>y;line[x][y]=1;}cout<<match()<<endl;return 0;
}

Dining

Cows are such finicky eaters. Each cow has a preference for certain foods and drinks, and she will consume no others.

Farmer John has cooked fabulous meals for his cows, but he forgot to check his menu against their preferences. Although he might not be able to stuff everybody, he wants to give a complete meal of both food and drink to as many cows as possible.

Farmer John has cooked F (1 ≤ F ≤ 100) types of foods and prepared D (1 ≤ D ≤ 100) types of drinks. Each of his N (1 ≤ N ≤ 100) cows has decided whether she is willing to eat a particular food or drink a particular drink. Farmer John must assign a food type and a drink type to each cow to maximize the number of cows who get both.

Each dish or drink can only be consumed by one cow (i.e., once food type 2 is assigned to a cow, no other cow can be assigned food type 2).

Input

Line 1: Three space-separated integers: NF, and D 
Lines 2.. N+1: Each line i starts with a two integers Fi and Di, the number of dishes that cow i likes and the number of drinks that cow i likes. The next Fi integers denote the dishes that cow i will eat, and theDi integers following that denote the drinks that cow i will drink.

Output

Line 1: A single integer that is the maximum number of cows that can be fed both food and drink that conform to their wishes

Sample Input

4 3 3
2 2 1 2 3 1
2 2 2 3 1 2
2 2 1 3 1 2
2 1 1 3 3

Sample Output

3

Hint

One way to satisfy three cows is: 
Cow 1: no meal 
Cow 2: Food #2, Drink #2 
Cow 3: Food #1, Drink #1 
Cow 4: Food #3, Drink #3 
The pigeon-hole principle tells us we can do no better since there are only three kinds of food or drink. Other test data sets are more challenging, of course.

#include <iostream>
#include <cstdio>
#include <algorithm>
#include <string>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <vector>
#include <ctime>
#include <cctype>
#include <bitset>
#include <utility>
#include <sstream>
#include <complex>
#include <iomanip>
#define inf 0x3f3f3f3f
typedef long long ll;
using namespace std;
//源点—— 食物 —— 牛 —— 牛 —— 饮品 —— 汇点。而所有的边的权值都是1 ,
//这样我们找到的最大流就一定是一只牛配上一种食物和一个饮品
int ceng[100010],ct,head[100010];
struct node
{int v;int cap;int next;
} G[100010*2];
void init()
{ct=0;memset(head,-1,sizeof(-1));
}
//静态邻接表建图
void add(int u,int v,int w)
{G[ct].v=v;G[ct].cap=w;G[ct].next=head[u];head[u]=ct++;G[ct].v=u;G[ct].cap=0;G[ct].next=head[v];head[v]=ct++;
}
//bfs分层
bool bfs(int s,int t)
{queue<int>q;memset(ceng,-1,sizeof(ceng));ceng[s]=0;q.push(s);while(!q.empty()){int u=q.front();q.pop();for(int i=head[u]; ~i; i=G[i].next){int v=G[i].v;if(G[i].cap>0&&ceng[v]==-1)//有剩余且该层未分配{ceng[v]=ceng[u]+1;q.push(v);}}}if(ceng[t]==-1)//层数不存在,说明增广路不存在return false;elsereturn true;
}
//dfs求增广路
int dfs(int u,int t,int f)
{if(u==t)return f;int flow=0,d;for(int i=head[u]; ~i; i=G[i].next){int v=G[i].v;if(G[i].cap>0&&ceng[u]<ceng[v]&&(d=dfs(v,t,min(G[i].cap,f)))){G[i].cap-=d;G[i^1].cap+=d;flow+=d;f-=d;if(!f)break;}}if(flow==0)ceng[u]=-1;return flow;
}
//dinic求最大流
int dinic(int s,int t)
{int flow=0;while(bfs(s,t))flow+=dfs(s,t,inf);return flow;
}
int main()
{int N,F,D,i,Fi,Di,x,S,T;cin>>N>>F>>D;init();S=0,T=F+N*2+D+1;for(i=1; i<=F; i++)add(S,i,1);for(i=1; i<=N; i++){cin>>Fi>>Di;while(Fi--){cin>>x;add(x,F+i,1);}add(F+i,F+N+i,1);while(Di--){cin>>x;add(F+N+i,F+N*2+x,1);}}for(i=1; i<=D; i++)add(F+N*2+i,T,1);cout<<dinic(S,T)<<endl;return 0;
}

Tunnel Warfare

During the War of Resistance Against Japan, tunnel warfare was carried out extensively in the vast areas of north China Plain. Generally speaking, villages connected by tunnels lay in a line. Except the two at the ends, every village was directly connected with two neighboring ones.

Frequently the invaders launched attack on some of the villages and destroyed the parts of tunnels in them. The Eighth Route Army commanders requested the latest connection state of the tunnels and villages. If some villages are severely isolated, restoration of connection must be done immediately!

Input

The first line of the input contains two positive integers n and m (n, m ≤ 50,000) indicating the number of villages and events. Each of the next m lines describes an event.

There are three different events described in different format shown below:

D x: The x-th village was destroyed.

Q x: The Army commands requested the number of villages that x-th village was directly or indirectly connected with including itself.

R: The village destroyed last was rebuilt.

Output

Output the answer to each of the Army commanders’ request in order on a separate line.

Sample Input

7 9
D 3
D 6
D 5
Q 4
Q 5
R
Q 4
R
Q 4

Sample Output

1
0
2
4
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <string>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <vector>
#include <ctime>
#include <cctype>
#include <bitset>
#include <utility>
#include <sstream>
#include <complex>
#include <iomanip>
#define inf 0x3f3f3f3f
#define node T[id]
#define lson T[id*2]
#define rson T[id*2+1]
typedef long long ll;
using namespace std;
struct Tree
{int lm;int rm;int l;int r;int tm;
} T[50010*4];
void jianshu(int id,int l,int r)
{node.l=l,node.r=r;node.lm=node.rm=node.tm=r-l+1;if(l==r)return ;int mid=(l+r)/2;jianshu(id*2,l,mid);jianshu(id*2+1,mid+1,r);
}
//x为修复或毁坏第x个村庄,bj是标记,为0表示破坏,为1表示修复
void gengxin(int id,int x,int bj)
{if(node.l==node.r){if(bj==0)node.lm=node.rm=node.tm=0;elsenode.lm=node.rm=node.tm=1;return ;}int mid=(node.l+node.r)/2;if(x<=mid)gengxin(id*2,x,bj);elsegengxin(id*2+1,x,bj);node.lm=lson.lm;node.rm=rson.rm;node.tm=max(lson.rm+rson.lm,max(lson.tm,rson.tm));//左结点的左区间满,那么当前结点的左区间还要再加上右结点的左区间if(lson.lm==lson.r-lson.l+1)node.lm+=rson.lm;if(rson.rm==rson.r-rson.l+1)node.rm+=lson.rm;
}
int query(int id,int x)
{if(node.l==node.r||node.tm==0||node.tm==node.r-node.l+1)return node.tm;int jg,mid=(node.l+node.r)/2;if(x<=mid){//如果x刚好处在左结点最右端的连续区间上面那么就还要再加上右结点对应最左端的连续区间if(x>=lson.r-lson.rm+1)jg=query(id*2,x)+query(id*2+1,mid+1);elsejg=query(id*2,x);}else{if(x<=rson.l+rson.lm-1)jg=query(id*2+1,x)+query(id*2,mid);elsejg=query(id*2+1,x);}return jg;
}
int main()
{char ch;int x,m,n;while(scanf("%d%d", &n, &m)!=EOF){stack<int> st;jianshu(1, 1, n);while (m--){scanf(" %c", &ch);if (ch=='D'){scanf("%d", &x);gengxin(1, x, 0);st.push(x);}else if (ch=='Q'){scanf("%d", &x);int jg = query(1, x);printf("%d\n", jg);}else{int tmp = st.top();st.pop();gengxin(1, tmp, 1);}}}return 0;
}

Bad Hair Day

Some of Farmer John's N cows (1 ≤ N ≤ 80,000) are having a bad hair day! Since each cow is self-conscious about her messy hairstyle, FJ wants to count the number of other cows that can see the top of other cows' heads.

Each cow i has a specified height hi (1 ≤ hi ≤ 1,000,000,000) and is standing in a line of cows all facing east (to the right in our diagrams). Therefore, cow i can see the tops of the heads of cows in front of her (namely cows i+1, i+2, and so on), for as long as these cows are strictly shorter than cow i.

Consider this example:

        =
=       =
=   -   =         Cows facing right -->
=   =   =
= - = = =
= = = = = =
1 2 3 4 5 6 

Cow#1 can see the hairstyle of cows #2, 3, 4
Cow#2 can see no cow's hairstyle
Cow#3 can see the hairstyle of cow #4
Cow#4 can see no cow's hairstyle
Cow#5 can see the hairstyle of cow 6
Cow#6 can see no cows at all!

Let ci denote the number of cows whose hairstyle is visible from cow i; please compute the sum of c1through cN.For this example, the desired is answer 3 + 0 + 1 + 0 + 1 + 0 = 5.

Input

Line 1: The number of cows, N
Lines 2..N+1: Line i+1 contains a single integer that is the height of cow i.

Output

Line 1: A single integer that is the sum of c 1 through cN.

Sample Input

6
10
3
7
4
12
2

Sample Output

5
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <string>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <vector>
#include <ctime>
#include <cctype>
#include <bitset>
#include <utility>
#include <sstream>
#include <complex>
#include <iomanip>
#define inf 0x3f3f3f3f
typedef long long ll;
using namespace std;
int n;
ll jg,x;
stack <ll>St;
int main(void)
{scanf("%d",&n);cin>>x;St.push(x);for(int i=1; i<n; i++){cin>>x;while(!St.empty()&&x>=St.top())St.pop();jg+=St.size();St.push(x);}cout<<jg<<endl;return 0;
}

青蛙的约会

两只青蛙在网上相识了,它们聊得很开心,于是觉得很有必要见一面。它们很高兴地发现它们住在同一条纬度线上,于是它们约定各自朝西跳,直到碰面为止。可是它们出发之前忘记了一件很重要的事情,既没有问清楚对方的特征,也没有约定见面的具体位置。不过青蛙们都是很乐观的,它们觉得只要一直朝着某个方向跳下去,总能碰到对方的。但是除非这两只青蛙在同一时间跳到同一点上,不然是永远都不可能碰面的。为了帮助这两只乐观的青蛙,你被要求写一个程序来判断这两只青蛙是否能够碰面,会在什么时候碰面。 
我们把这两只青蛙分别叫做青蛙A和青蛙B,并且规定纬度线上东经0度处为原点,由东往西为正方向,单位长度1米,这样我们就得到了一条首尾相接的数轴。设青蛙A的出发点坐标是x,青蛙B的出发点坐标是y。青蛙A一次能跳m米,青蛙B一次能跳n米,两只青蛙跳一次所花费的时间相同。纬度线总长L米。现在要你求出它们跳了几次以后才会碰面。

Input

输入只包括一行5个整数x,y,m,n,L,其中x≠y < 2000000000,0 < m、n < 2000000000,0 < L < 2100000000。

Output

输出碰面所需要的跳跃次数,如果永远不可能碰面则输出一行"Impossible"

Sample Input

1 2 3 4 5

Sample Output

4
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <string>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <vector>
#include <ctime>
#include <cctype>
#include <bitset>
#include <utility>
#include <sstream>
#include <complex>
#include <iomanip>
#define inf 0x3f3f3f3f
typedef long long ll;
using namespace std;
ll x,y,m,n,L;
ll exgcd(ll a,ll b,ll &x,ll &y)
{if(b==0){x=1;y=0;return a;}ll tx,ty;ll d=exgcd(b,a%b,tx,ty);x=ty;y=tx-(a/b)*ty;return d;
}
int main()
{cin>>x>>y>>m>>n>>L;if(m==n)cout<<"Impossible"<<endl;else{if(m<n){swap(m,n);swap(x,y);}ll xx,yy,d=exgcd(m-n,L,xx,yy);ll cha=y-x;
//        cout<<d<<' '<<xx<<' '<<yy<<endl;if(cha%d)cout<<"Impossible"<<endl;elsecout<<((xx*cha/d)%(L/d)+(L/d))%(L/d)<<endl;}return 0;
}

Balanced Lineup

For the daily milking, Farmer John's N cows (1 ≤ N ≤ 50,000) always line up in the same order. One day Farmer John decides to organize a game of Ultimate Frisbee with some of the cows. To keep things simple, he will take a contiguous range of cows from the milking lineup to play the game. However, for all the cows to have fun they should not differ too much in height.

Farmer John has made a list of Q (1 ≤ Q ≤ 200,000) potential groups of cows and their heights (1 ≤ height ≤ 1,000,000). For each group, he wants your help to determine the difference in height between the shortest and the tallest cow in the group.

Input

Line 1: Two space-separated integers, N and Q
Lines 2.. N+1: Line i+1 contains a single integer that is the height of cow i 
Lines N+2.. NQ+1: Two integers A and B (1 ≤ A ≤ B ≤ N), representing the range of cows from A to Binclusive.

Output

Lines 1.. Q: Each line contains a single integer that is a response to a reply and indicates the difference in height between the tallest and shortest cow in the range.

Sample Input

6 3
1
7
3
4
2
5
1 5
4 6
2 2

Sample Output

6
3
0
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <string>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <vector>
#include <ctime>
#include <cctype>
#include <bitset>
#include <utility>
#include <sstream>
#include <complex>
#include <iomanip>
#define inf 1e9
typedef long long ll;
using namespace std;
#define maxn 50010
int c[maxn << 2][2];
void built(int o, int l, int r, int id, int v)
{if(l == r){c[o][0] = c[o][1] = v;return;}int mid = l + r >> 1;if(id <= mid)built(o << 1, l, mid, id, v);if(id > mid)built(o << 1 | 1, mid + 1, r, id, v);c[o][0] = min(c[o << 1][0], c[o << 1 | 1][0]);c[o][1] = max(c[o << 1][1], c[o << 1 | 1][1]);
}
int quary1(int o, int l, int r, int L, int R)
{if(l >= L && r <= R)return c[o][0];int mid = l + r >> 1, ans =inf;if(mid >= L)ans = min(ans, quary1(o << 1, l, mid, L, R));if(mid < R)ans = min(ans, quary1(o << 1 | 1, mid + 1, r, L, R));return ans;
}
int quary2(int o, int l, int r, int L, int R)
{if(l >= L && r <= R)return c[o][1];int mid = l + r >> 1, ans = 0;if(mid >= L)ans = max(ans, quary2(o << 1, l, mid, L, R));if(mid < R)ans = max(ans, quary2(o << 1 | 1, mid + 1, r, L, R));return ans;
}
int main()
{int n, q, x, l, r;scanf("%d%d", &n, &q);memset(c, 0, sizeof(c));for(int i = 1; i <= n; ++i){scanf("%d", &x);built(1, 1, n, i, x);}while(q--){scanf("%d%d", &l, &r);printf("%d\n", quary2(1, 1, n, l, r) - quary1(1, 1, n, l, r));}return 0;
}

RMQ算法实现:

#include <iostream>
#include <cstdio>
#include <algorithm>
#include <string>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <iomanip>
#define inf 0x3f3f3f3f
typedef long long ll;
using namespace std;
int s[50010],dpmx[50010][50],dpmi[50010][50];
int N,Q,A,B;
void init()
{for(int i=1; i<=N; i++){dpmx[i][0]=s[i];dpmi[i][0]=s[i];}for(int j=1; (1<<j)<=N; j++){for(int i=1; i+(1<<j)-1<=N; i++){dpmx[i][j]=max(dpmx[i][j-1],dpmx[i+(1<<j-1)][j-1]);dpmi[i][j]=min(dpmi[i][j-1],dpmi[i+(1<<j-1)][j-1]);}}
}
int RMQ(int l,int r)
{int k=log2(r-l+1);int mx=max(dpmx[l][k],dpmx[r-(1<<k)+1][k]);int mi=min(dpmi[l][k],dpmi[r-(1<<k)+1][k]);return mx-mi;
}
int main()
{scanf("%d%d",&N,&Q);for(int i=1; i<=N; i++)scanf("%d",&s[i]);init();while(Q--){scanf("%d%d",&A,&B);printf("%d\n",RMQ(A,B));}return 0;
}

Trailing Zeroes (I)

We know what a base of a number is and what the properties are. For example, we use decimal number system, where the base is 10 and we use the symbols - {0, 1, 2, 3, 4, 5, 6, 7, 8, 9}. But in different bases we use different symbols. For example in binary number system we use only 0 and 1. Now in this problem, you are given an integer. You can convert it to any base you want to. But the condition is that if you convert it to any base then the number in that base should have at least one trailing zero that means a zero at the end.

For example, in decimal number system 2 doesn't have any trailing zero. But if we convert it to binary then 2 becomes (10)2 and it contains a trailing zero. Now you are given this task. You have to find the number of bases where the given number contains at least one trailing zero. You can use any base from two to infinite.

Input

Input starts with an integer T (≤ 10000), denoting the number of test cases.

Each case contains an integer N (1 ≤ N ≤ 1012).

Output

For each case, print the case number and the number of possible bases where N contains at least one trailing zero.

Sample Input

3

9

5

2

Sample Output

Case 1: 2

Case 2: 1

Case 3: 1

Note

For 9, the possible bases are: 3 and 9. Since in base 39 is represented as 100, and in base 99 is represented as 10. In both bases, 9 contains a trailing zero.

#include <iostream>
#include <cstdio>
#include <algorithm>
#include <string>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <vector>
#include <ctime>
#include <cctype>
#include <bitset>
#include <utility>
#include <sstream>
#include <complex>
#include <iomanip>
#define inf 0x3f3f3f3f
typedef long long LL;
using namespace std;
LL prime[1000010],t,vis[1000010],T,ct=1;
void db()
{LL i,j;for(i=2; i<1000010; i++){if(!vis[i]){for(j=i*i; j<1000010; j+=i)vis[j]=1;prime[t++]=i;}}
}
int main()
{db();scanf("%lld",&T);while(T--){LL i,m,jg=1,s;LL num,n;scanf("%lld",&n);num=n;for(i=0; i<t&&prime[i]*prime[i]<=num; i++){if(num%prime[i]==0){s=0;while(num%prime[i]==0){s++;num/=prime[i];}jg*=(s+1);}}if(num>1)jg*=2;printf("Case %lld: %lld\n",ct++,jg-1);}return 0;
}

Digits of Factorial

Factorial of an integer is defined by the following function

f(0) = 1

f(n) = f(n - 1) * n, if(n > 0)

So, factorial of 5 is 120. But in different bases, the factorial may be different. For example, factorial of 5 in base 8 is 170.

In this problem, you have to find the number of digit(s) of the factorial of an integer in a certain base.

Input

Input starts with an integer T (≤ 50000), denoting the number of test cases.

Each case begins with two integers n (0 ≤ n ≤ 106) and base (2 ≤ base ≤ 1000). Both of these integers will be given in decimal.

Output

For each case of input you have to print the case number and the digit(s) of factorial n in the given base.

Sample Input

5

5 10

8 10

22 3

1000000 2

0 100

Sample Output

Case 1: 3

Case 2: 5

Case 3: 45

Case 4: 18488885

Case 5: 1

#include <iostream>
#include <cstdio>
#include <algorithm>
#include <string>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <vector>
#include <ctime>
#include <cctype>
#include <bitset>
#include <utility>
#include <sstream>
#include <complex>
#include <iomanip>
#define inf 0x3f3f3f3f
typedef long long ll;
using namespace std;
double sum[1000010];
//求输入的N在base进制下阶层的位数,公式为:logk(N!)+1然后用换底公式展开
int T,n,base,ct=1;
void db()
{for(int i=1; i<=1000000; i++)sum[i]=sum[i-1]+log(i);
}
int main()
{scanf("%d",&T);db();while(T--){scanf("%d%d",&n,&base);if(n==0)printf("Case %d: 1\n",ct++);elseprintf("Case %d: %d\n",ct++,(int)(sum[n]/log(base)+1));}return 0;
}

Cows and Cars

#include <iostream>
#include <cstdio>
#include <algorithm>
#include <string>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <vector>
#include <ctime>
#include <cctype>
#include <bitset>
#include <utility>
#include <sstream>
#include <complex>
#include <iomanip>
#define inf 0x3f3f3f3f
typedef long long ll;
using namespace std;
double cow,car,show,jg;
int main(){while(~scanf("%lf%lf%lf",&cow,&car,&show)){//开始若选择牛double jg1=(cow/(cow+car))*(car/(car+cow-show-1));//开始选择汽车double jg2=(car/(cow+car))*((car-1)/(car+cow-show-1));jg=jg1+jg2;printf("%.5f\n",jg);}return 0;
}

S-Trees

#include <iostream>
#include <cstdio>
#include <algorithm>
#include <string>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <vector>
#include <ctime>
#include <cctype>
#include <bitset>
#include <utility>
#include <sstream>
#include <complex>
#include <iomanip>
#define inf 0x3f3f3f3f
typedef long long ll;
using namespace std;
char s[10],yz[1010],ss[10],jg[1010];
int p[10],m,n,t,ct=1;
int kpow(int a,int b)
{int ans=1;while(b){if(b&1)ans*=a;a*=a;b>>=1;}return ans;
}
char output()
{int l=0,r=t;for(int i=0; i<n; i++){if(ss[p[i]]=='0')r=(l+r)/2;elsel=(l+r)/2;}return yz[l];
}
int main()
{while(scanf("%d",&n)&&n!=0){memset(jg,0,sizeof(jg));getchar();for(int i=0; i<n; i++){scanf("%s",s);p[i]=s[1]-'1';}t = kpow(2,n);scanf("%s",yz);scanf("%d",&m);getchar();for(int i = 0; i < m; i++){scanf("%s",ss);jg[i]=output();}printf("S-Tree #%d:\n",ct++);for(int i=0; i<m; i++)printf("%c",jg[i]);printf("\n\n");}return 0;
}

YTU每周训练----数据结构+数论+图论相关推荐

  1. BUCTOJ - 2023上半年ACM蓝桥杯每周训练题-1-A~K题C++Python双语版

    文章目录 BUCTOJ - 2023上半年ACM&蓝桥杯每周训练题-1-A~K题C++Python双语版 前言 问题 A: 1.2 神奇兔子数列 题目描述 输入 输出 解题思路 AC代码 C+ ...

  2. SDUT 2141 【TEST】数据结构实验图论一:基于邻接矩阵的广度优先搜索遍历

    数据结构实验图论一:基于邻接矩阵的广度优先搜索遍历 Time Limit: 1000MS Memory Limit: 65536KB Submit Statistic Discuss Problem ...

  3. 关于数据结构和图论的一些入门攻略

    我是负责我们队数据结构和图论的,在集训队做了一个多月的题,应该算是图论和数据结构入门了吧,这里我推荐一些图论和数据结构的算法学习顺序(我的见解),如果对这一方面有兴趣的可以看一看.(日常菜的抠脚不想去 ...

  4. 每周训练5小时,自信从容进大厂 | 20年码龄的技术VC大咖为你的面试指点迷津

    3月4日(周四).7日(周日)的两场直播都已经结束,共有上百位同学在线观看,感谢猿粉们的积极参与! 技术大咖"白月光"老师通过讲解三位学生的技术成长经历,给大厂面试划重点,我们一起 ...

  5. 【csp模拟赛2】黑莲花--数据结构+数论

    没有什么能够阻挡,你对被阿的向往.天天 AK 的生涯,你的心了无牵挂. 虐过大佬的比赛,也曾装弱装逼.当你低头的瞬间,才发现旁边的人. 把你的四肢抬起来,使劲地往门上撞.盛开着永不凋零,黑莲花. -- ...

  6. 一起开心2020暑假训练第二周 图论(模板题)

    比赛链接: 文章目录 A HDU 1285 一 B HDU 1863 起 C POJ 2387 开 D POJ 1502 心 E HDU 5922 图 F HDU 2112 论 A HDU 1285 ...

  7. 刘汝佳训练指南——数论专题知识点总结:

    数论是一个神奇的东西,各种结论都很经典,有些懂,有些自己还不是很懂. 接下来就一个一个的介绍吧. 第一.素数,素数本身就是一个很让人惊奇的数,因为它代表的是唯一,自己就有连个因数,一个是1,一个是自己 ...

  8. 使用训练数据结构代替注意力机制之训练一个小说

    #!/usr/bin/python # -*- coding: utf-8 -*- import torch from torch import nn import matplotlib.pyplot ...

  9. 使用训练数据结构代替注意力机制

    #!/usr/bin/python # -*- coding: utf-8 -*- import torch from torch import nn import matplotlib.pyplot ...

最新文章

  1. 计算机网络的组成相关,计算机网络的组成
  2. 赢在微点答案专区英语_少儿英语课堂 语法教学游戏 全集
  3. spring的事务隔离_spring事务基础及常见问题详解
  4. map-based exploration of intrinsic shape differences and variability
  5. 矩阵分析与应用(二)
  6. iWebOffice2015入门(一)
  7. win10 计算机右键管理,win10系统右键菜单管理的步骤介绍
  8. 用计算机问你叫什么名字,计算器功能有哪些呢
  9. Java毕业设计-个性影片/电影推荐系统
  10. AQS框架原文翻译 - The java.util.concurrent Synchronizer Framework
  11. 900万!!!!!!!!这也太强了吧!!!我的老天!!!!!!!!!!
  12. 南邮 | 计算机图形学大作业:Skybox + Shadow volume
  13. 北美年轻人也渴望新的社交软件?「Vibe」想用校园社群 Story 打开市场
  14. Linux 系统编程笔记-(1)基本概念
  15. ORA-00054问题解决
  16. 需求分析报告应该包含哪些部分_2020最新抖音用户画像分析报告:粉丝都有哪些特点和需求?...
  17. 4大重要营销概念的正本清源
  18. 计算机图形学——绘制钻石图案
  19. 零代码平台在大型企业的进化之路
  20. 非最小相位系统;频率特性的对称性

热门文章

  1. Linux 块驱动之一
  2. 计算机主板 大 小,电脑主板选大的还是小的比较好?
  3. 计算机社团活动丰富多彩,社团活动丰富多彩 校园文化彰显特色
  4. ElastAlert规则
  5. 八种生物成像技术,你青睐谁?
  6. strtod() 函数
  7. Qt安装及配置资源链接
  8. 分布式多通道相机同时拍照系统
  9. 3.6 杭电复试题2010
  10. YOLO系列目标检测算法-YOLOv7