/**A*/
#include <bits/stdc++.h>
using namespace std;
int main(){
int t;
cin>>t;while(t--){
double p;
cin>>p;
double w=p,e=p,m=1,cnt=1;while(m!=0){
cnt++;
m*=(1-w);
w=min(w+p,1.0);
e+=w*m*cnt;}printf("%.6lf\n",(double)1/e);}return0;}
B题 小Y的游戏
/**B*/
#include <bits/stdc++.h>
using namespace std;
int main(){
int t;
cin>>t;while(t--){
int a,b,c;
cin>>a>>b>>c;
bool flag=1;if(a*b*c==163)flag=0;if(a*b+c==163)flag=0;if(a*b-c==163)flag=0;if(a+b*c==163)flag=0;if(a-b*c==163)flag=0;if(!flag)
cout<<1<<endl;else
cout<<0<<endl;}return0;}
C题 灭霸打响指
/**C*/
#include <bits/stdc++.h>
using namespace std;
int main(){
int t;
cin>>t;while(t--){
int n;
cin>>n;
double sum=0;for(int i=0;i<n;i++){
double num;
cin>>num;
sum+=num;}printf("%.2lf\n",sum*0.5);}return0;}
D题 将军旗
/**D*/
#include <bits/stdc++.h>
using namespace std;const int maxn=1e2*4+5;voidcnt(int n,int m,int amaze[][maxn],int bmaze[][maxn],int *acnt,int *bcnt){for(int i=1;i<=n;i++)for(int j=1;j<=m;j++){*acnt+=amaze[i][j];*bcnt+=bmaze[i][j];}}
int main(){
int t;
cin>>t;while(t--){
int n,m;
cin>>n>>m;
int ax,ay,bx,by;
int amaze[maxn][maxn],bmaze[maxn][maxn];memset(amaze,0,sizeof(amaze));memset(bmaze,0,sizeof(bmaze));
cin>>ax>>ay;
cin>>amaze[ax][ay];
cin>>bx>>by;
cin>>bmaze[bx][by];
int acnt=0,bcnt=0;
int flag=0;
int q;
cin>>q;for(int i=0;i<q;i++){
int x,y;
int num;
char c;
cin>>x>>y>>c;
amaze[ax][ay]++;
num=amaze[x][y]-1;
amaze[x][y]=1;if(c=='U')x--;if(c=='D')x++;if(c=='L')y--;if(c=='R')y++;
num+=amaze[x][y];if(num>bmaze[x][y]){
amaze[x][y]=num-bmaze[x][y];
bmaze[x][y]=0;}else{
amaze[x][y]=0;
bmaze[x][y]-=num;}if(bmaze[bx][by]==0&&!flag){
flag=1;cnt(n,m,amaze,bmaze,&acnt,&bcnt);}
cin>>x>>y>>c;
bmaze[bx][by]++;
num=bmaze[x][y]-1;
bmaze[x][y]=1;if(c=='U')x--;if(c=='D')x++;if(c=='L')y--;if(c=='R')y++;
num+=bmaze[x][y];if(num>amaze[x][y]){
bmaze[x][y]=num-amaze[x][y];
amaze[x][y]=0;}else{
bmaze[x][y]=0;
amaze[x][y]-=num;}if(amaze[ax][ay]==0&&!flag){
flag=2;cnt(n,m,amaze,bmaze,&acnt,&bcnt);}}if(flag==0){
cout<<"draw!"<<endl;cnt(n,m,amaze,bmaze,&acnt,&bcnt);}elseif(flag==1)
cout<<"Alice wins!!!"<<endl;else
cout<<"Bob wins!!"<<endl;
cout<<acnt<<' '<<bcnt<<endl;}return0;}
E题 小手冰凉和oja的新游戏
/**E*/
#include <bits/stdc++.h>
using namespace std;
int main(){
int t;
cin>>t;while(t--){
string s[107];
int n,k=0;
cin>>n;for(int i=0;i<n;i++){
int m;
cin>>m;
string t="";for(int j=0;j<m;j++){
int num;
cin>>num;
t+=(char)(num+'0');}
bool flag=1;for(int j=0;j<k;j++){if(s[j].find(t)!=-1){
flag=0;break;}if(t.find(s[j])!=-1){
flag=0;
s[j]=t;break;}}if(flag){
s[k++]=t;}}
bool flag=1;for(int i=0;i<k;i++){if(s[i].length()%2==0){
flag=0;break;}}if(flag)
cout<<"Xsblwins!"<<endl;else
cout<<"Ojawins!"<<endl;}return0;}
F题 小Y的数列
/**F*/
#include <bits/stdc++.h>
using namespace std;const int maxn=1e3*2+5;;const int mod=1e4+7;
int str[maxn][maxn];
int main(){
int t;
cin>>t;while(t--){
int n,m;memset(str,0,sizeof(str));
cin>>n>>m;for(int i=0;i<n;i++)for(int j=0;j<m;j++){if(i==0)
str[i][j]=1;else{if(j==0)
str[i][j]=1;else
str[i][j]=(str[i][j-1]+str[i-1][j])%mod;}}
cout<<str[n-1][m-1]<<endl;}return0;}
G题 弹珠卡牌
/**G*/
#include <bits/stdc++.h>
using namespace std;const int maxn=1e6+5;
int ball[maxn];
int card[maxn];
int main(){
int tt;
cin>>tt;while(tt--){memset(card,0,sizeof(card));memset(ball,0,sizeof(ball));
int n,p,t;
cin>>n>>p>>t;
int bp=t;for(int i=0;i<n;i++)
cin>>ball[i];
int m;
cin>>m;for(int i=0;i<m;i++){
int num,sum;
cin>>num>>sum;
card[num]=card[num]==0?sum:min(sum,card[num]);}
int allneed=0;for(int i=0;i<=p;i++)
allneed+=card[i];
int cnt=0;while(allneed){
bool flag=1;for(int i=0;i<t;i++){if(card[ball[i]]!=0){
cnt++;
flag=0;
card[ball[i]]--;
allneed--;if(bp<n){
ball[i]=ball[bp++];}else
ball[i]=p+1;}}if(flag){if(bp<n){
cnt++;
ball[0]=ball[bp++];if(card[0]!=0){
card[0]--;
allneed--;}}else{if(t>0&&card[0]!=0){
card[0]--;
allneed--;
t--;
cnt++;}elsebreak;}}}if(allneed==0)
cout<<cnt<<endl;else
cout<<-1<<endl;}return0;}
H题 回文串文回
/**H*/
#include <bits/stdc++.h>
using namespace std;
int main(){
int t;
cin>>t;while(t--){
string s;
cin>>s;
int maxlen=0;for(int i=0;i<s.length();i++){for(int j=s.length()-1;j>i+1+maxlen;j--){
int p=0;while(i+p+1<j-p&&s[i+p]==s[j-p])
p++;
maxlen=max(p*2,maxlen);}}
cout<<maxlen<<endl;}return0;}
I题 超级无敌动态树模板
/**I*/
#include <bits/stdc++.h>
using namespace std;const int maxn =1e4+5;
int dis[maxn],book[maxn];
int head[maxn],cnt;const int INF=0x3f3f3f3f;
struct Edge{
int to,w,next;}edge[maxn*5+5];
struct node{
int index,dist;
friend bool operator <(node a,node b){return a.dist>b.dist;}};
priority_queue<node> myq;voidadd_edge(int u,int v,int w){
edge[cnt].to=v;
edge[cnt].w=w;
edge[cnt].next=head[u];
head[u]=cnt++;
edge[cnt].to=u;
edge[cnt].w=w;
edge[cnt].next=head[v];
head[v]=cnt++;}voiddijkstra(int n){
dis[1]=0;for(int i=2;i<=n;i++)dis[i]=INF;
myq.push(node{1,0});while(!myq.empty()){
node x=myq.top();
myq.pop();
int u=x.index;if(book[u])continue;
book[u]=1;for(int j=head[u];j;j=edge[j].next){if(dis[edge[j].to]>dis[u]+edge[j].w){
dis[edge[j].to]=dis[u]+edge[j].w;
myq.push(node{edge[j].to,dis[edge[j].to]});}}}}voidadd(int n){
int u,v,w;scanf("%d %d %d",&u,&v,&w);add_edge(u,v,w);memset(book,0,sizeof(book));dijkstra(n);}voidget(){
int p;
cin>>p;if(dis[p]==INF){
cout<<-1<<endl;}else{
cout<<dis[p]<<endl;}}void_(int T){while(T--){
int n,m,q;
cnt=1;memset(head,0,sizeof(head));for(int i=0;i<maxn*5+5;i++){}
cin>>n>>m>>q;memset(book,0,sizeof(book));while(m--){
int u,v,w;
cin>>u>>v>>w;add_edge(u,v,w);}dijkstra(n);while(q--){
int op;scanf("%d",&op);switch(op){case1:add(n);break;case2:get();break;}}}}
int main(){
int T;cin>>T;_(T);return0;}
J题 可口可乐
/**J*/
#include <bits/stdc++.h>
using namespace std;
int main(){
int t;
cin>>t;while(t--){
int n;
cin>>n;
int m1coke=0,m2coke=0;while(n--){
int num;
cin>>num;if(m2coke==0)
m2coke=num;elseif(m1coke==0)
m1coke=num;else{
m2coke=m2coke<num?num:m2coke;if(m1coke<m2coke)swap(m1coke,m2coke);}}
cout<<m1coke+m2coke<<endl;}return0;}
K题 菓粒橙小孩
/**K*/
#include <bits/stdc++.h>
using namespace std;
int main(){
int t;
cin>>t;while(t--){
long long n,m;
cin>>n>>m;
string s;
cin>>s;for(int i=0;i<s.length();i++)if(s[i]=='1')
n--;if(n==0)
n=1;
cout<<n*m<<endl;}return0;}