gym 100952

A

 #include <iostream>
#include<cstdio>
#include<cmath>
#include<cstring>
#include<algorithm>
#include<map>
#include<queue>
#include<stack>
#include<vector>
#include<set>
using namespace std;
#define PI acos(-1.0)
typedef long long ll;
typedef pair<int,int> P;
const int maxn=1e5+,maxm=1e5+,inf=0x3f3f3f3f,mod=1e9+;
const ll INF=1e13+;
priority_queue<P,vector<P>,greater<P> >que;
struct edge
{
int from,to;
int cost;
};
int main()
{
int T;
int h1,h2,m1,m2,s1,s2;
scanf("%d",&T);
while(T--)
{
scanf("%d%d%d%d%d%d",&h1,&m1,&s1,&h2,&m2,&s2);
int sign=;
if(h1<h2) sign=;
else if(h1>h2) sign=;
else
{
if(m1<m2) sign=;
else if(m1>m2) sign=;
else
{
if(s1<s2) sign=;
else if(s1>s2) sign=;
}
}
if(sign==) cout<<"Player1"<<endl;
else if(sign==) cout<<"Player2"<<endl;
else cout<<"Tie"<<endl;
}
return ;
}

B

 #include <iostream>
#include<cstdio>
#include<cmath>
#include<cstring>
#include<algorithm>
#include<map>
#include<queue>
#include<stack>
#include<vector>
#include<set>
using namespace std;
#define PI acos(-1.0)
typedef long long ll;
typedef pair<int,int> P;
const int maxn=1e5+,maxm=1e5+,inf=0x3f3f3f3f,mod=1e9+;
const ll INF=1e13+;
priority_queue<P,vector<P>,greater<P> >que;
struct edge
{
int from,to;
int cost;
};
int main()
{
int T;
scanf("%d",&T);
while(T--)
{
int n,m;
scanf("%d%d",&n,&m);
int ans=,cou=,sign=;
while(true)
{
if(sign>m) break;
cou=cou+sign;
ans++;
sign*=;
if(cou>=n) break;
}
////cout<<cou<<" "<<sign<<endl;
if(cou>=n) cout<<ans<<endl;
else
{
ans+=(n-cou)/m;
if((n-cou)%m) ans++;
cout<<ans<<endl;
}
}
return ;
}

C

 #include <iostream>
#include<cstdio>
#include<cmath>
#include<cstring>
#include<algorithm>
#include<map>
#include<queue>
#include<stack>
#include<vector>
#include<set>
using namespace std;
#define PI acos(-1.0)
typedef long long ll;
typedef pair<int,int> P;
const int maxn=1e5+,maxm=1e5+,inf=0x3f3f3f3f,mod=1e9+;
const ll INF=1e13+;
priority_queue<P,vector<P>,greater<P> >que;
struct edge
{
int from,to;
int cost;
};
char s[maxn];
int main()
{
int T;
scanf("%d",&T);
while(T--)
{
int n,p;
scanf("%d%d",&n,&p);
getchar();
for(int i=; i<=n; i++) scanf("%c",&s[i]);
//cout<<s+1<<endl;
int ans=;
int l=inf,r=;
for(int i=; i<=n/; i++)
{
if(s[i]!=s[n+-i])
{
l=min(l,i);
r=max(r,i);
}
if(s[i]<=s[n+-i]) swap(s[i],s[n+-i]);
ans+=min(s[i]-s[n+-i],s[n+-i]+-s[i]);
}
if(p>n/) p=n+-p;
if(l>r) cout<<<<endl;
else
printf("%d\n",ans+r-l+min(abs(p-l),abs(p-r)));
}
return ;
}

D

 #include <iostream>
#include <cstdio>
#include <cmath>
#include <string>
#include <cstring>
#include <algorithm>
#include <queue>
#include <map>
#include <set>
#include <stack>
#include <sstream>
#include <vector> using namespace std; typedef long long ll;
/****************************************/
const int N = + ;
const int MOD = (int)1e9 + ;
int F[N], Finv[N], inv[N];//F是阶乘,Finv是逆元的阶乘
void init(){
inv[] = ;
for(int i = ; i < N; i ++){
inv[i] = (MOD - MOD / i) * 1ll * inv[MOD % i] % MOD;
}
F[] = Finv[] = ;
for(int i = ; i < N; i ++){
F[i] = F[i-] * 1ll * i % MOD;
Finv[i] = Finv[i-] * 1ll * inv[i] % MOD;
}
}
int comb(int n, int m){//comb(n, m)就是C(n, m)
if(m < || m > n) return ;
return F[n] * 1ll * Finv[n - m] % MOD * Finv[m] % MOD;
}
int main(){
init();
int t,n,m,k,d;
scanf("%d",&t);
while(t--){
scanf("%d%d%d%d",&n,&m,&k,&d);
int ans=comb(n,m),x,da=,xiao=;
for(int i=;i<n;i++){
scanf("%d",&x);
if(x>=d)da++;
}
xiao=n-da;
for(int i=k-;i>=;i--){
ans=(ans+MOD-(comb(da,i)*1ll*comb(xiao,m-i))%MOD)%MOD;
}
printf("%d\n",ans);
}
}

E

 #include <iostream>
#include<cstdio>
#include<cmath>
#include<cstring>
#include<algorithm>
#include<map>
#include<queue>
#include<stack>
#include<vector>
#include<set>
using namespace std;
#define PI acos(-1.0)
typedef long long ll;
typedef pair<int,string> P;
const int maxn=1e5+,maxm=1e5+,inf=0x3f3f3f3f,mod=1e9+;
const ll INF=1e13+;
priority_queue<P,vector<P>,greater<P> >q;
struct edge
{
int from,to;
int cost;
};
int n,m,t;
int pa[];
int flag[][];
int sign[][];
int vis[];
int ans=;
void dfs(int x,int y,int cou)
{
//cout<<x<<" "<<y<<" "<<cou<<endl;
if(x>n)
{
if(cou==t) ans++;
return;
}
for(int k=; k<=t; k++)
{
if(k&&vis[k]) continue;
if(x->=&&flag[k][sign[x-][y]]) continue;
if(y->=&&flag[k][sign[x][y-]]) continue;
sign[x][y]=k;
vis[k]=;
dfs(y==m?x+:x,y==m?:y+,k==?cou:cou+);
sign[x][y]=;
vis[k]=;
}
}
int main()
{
int T;
scanf("%d",&T);
while(T--)
{
scanf("%d%d%d",&n,&m,&t);
int p;
scanf("%d",&p);
for(int i=; i<=t; i++) pa[i]=i;
memset(flag,,sizeof(flag));
while(p--)
{
int a,b;
scanf("%d%d",&a,&b);
flag[a][b]=flag[b][a]=;
}
ans=;
memset(vis,,sizeof(vis));
memset(sign,,sizeof(sign));
dfs(,,);
if(ans==) cout<<"impossible"<<endl;
else cout<<ans<<endl;
}
return ;
}

F

 #include <iostream>
#include<cstdio>
#include<cmath>
#include<cstring>
#include<algorithm>
#include<map>
#include<queue>
#include<stack>
#include<vector>
#include<set>
using namespace std;
#define PI acos(-1.0)
typedef long long ll;
typedef pair<int,string> P;
const int maxn=1e5+,maxm=1e5+,inf=0x3f3f3f3f,mod=1e9+;
const ll INF=1e13+;
priority_queue<P,vector<P>,greater<P> >q;
struct edge
{
int from,to;
int cost;
};
map<string,map<string,int> >G;
map<string,int>dist;
struct node
{
string str;
int ss;
}N[];
bool cmp(struct node aa,struct node bb)
{
if(aa.ss!=bb.ss)
return aa.ss<bb.ss;
else
return aa.str<bb.str;
}
void dij(string s)
{
dist[s]=;
q.push(P(dist[s],s));
while(!q.empty())
{
P p=q.top();
q.pop();
string u=p.second;
map<string,int> ::iterator it;
for(it=G[u].begin(); it!=G[u].end(); it++)
{
if((*it).second==) continue;
//cout<<(*it).first<<" "<<(*it).second<<endl;
string v=(*it).first;
if(dist[v]>dist[u]+)
{
dist[v]=dist[u]+;
q.push(P(dist[v],v));
}
}
}
}
int main()
{
int T;
scanf("%d",&T);
while(T--)
{
int n;
scanf("%d",&n);
string s="Ahmad";
G.clear();
dist.clear();
int jishu=;
for(int i=; i<=n; i++)
{
string a,b,c;
cin>>a>>b>>c;
if(dist[a]==){
N[jishu++].str=a;
dist[a]=inf;
}
if(dist[b]==){
N[jishu++].str=b;
dist[b]=inf;
}
if(dist[c]==){
N[jishu++].str=c;
dist[c]=inf;
}
G[a][b]=G[b][a]=G[b][c]=G[c][b]=G[a][c]=G[c][a]=;
}
dij(s);
cout<<jishu<<endl;
for(int i=;i<jishu;i++)
N[i].ss=dist[N[i].str];
sort(N,N+jishu,cmp);
for(int i=;i<jishu;i++){
if(N[i].ss>=inf)
cout<<N[i].str<<" "<<"undefined"<<endl;
else
cout<<N[i].str<<" "<<N[i].ss<<endl;
}
}
return ;
}

G

 #include <iostream>
#include <cstdio>
#include <cmath>
#include <string>
#include <cstring>
#include <algorithm>
#include <queue>
#include <map>
#include <set>
#include <stack>
#include <sstream>
#include <vector>
#define PI acos(-1.0)
#define N 5e6+10
#define M 1000000007
#define inf 1e9
#define eps 1e-8
#define dazhi 2147483647
using namespace std; typedef long long ll; ll pow(ll a,ll b,ll p){ll sum=;for(a%=p;b;a=a*a%p,b>>=)if(b&)sum=sum*a%p;return sum;}
ll phi(ll n){ll i,re=n;for(i=;i*i<=n;i++)if(n%i==){re=re/i*(i-);while(n%i==)n/=i;}if(n>)re=re/n*(n-);return re%M;}
void exgcd(ll a,ll b,ll &x,ll &y){if(!b){x=;y=;return;}exgcd(b,a%b,y,x);y-=x*(a/b);}
ll gcd(ll a,ll b){return b==?a:gcd(b,a%b);} /****************************************/
int main()
{ int t,n;
scanf("%d",&t);
while(t--)
{
scanf("%d",&n);
if(n==)printf("Bob\n");
else printf("Alice\n");
}
}

H

 #include<iostream>
#include<cstdio>
#include<cmath>
#include<cstring>
#include<algorithm>
#include<map>
#include<queue>
#include<stack>
#include<vector>
#include<bitset>
#include<set>
#define ll __int64
#define mod 100000000
#define N 5e6+10
#define M 1e
using namespace std;
ll a[]={ ,
,
,
,
,
,
,
,
,
,
,
,
,
,
,
,
,
,
,
,
,
,
,
,
,
,
, ,
,
,
,
,
,
,
,
,
,
,
,
,
,
,
,
,
,
,
,
,
,
,
,
,
,
,
,
,
,
,
,
,
,
,
,
,
,
,
,
,
,
,
,
,
,
,
,
,
,
,
,
,
,
,
,
,
,
,
,
,
,
,
,
,
,
,
,
,
,
,
,
,
,
,
,
,
,
,
,
,
,
,
,
,
,
,
,
,
,
,
,
,
,
,
,
,
,
,
,
,
,
,
,
,
,
,
,
,
,
,
,
,
,
,
,
,
,
,
,
,
,
,
,
,
,
,
,
,
,
,
,
,
,
,
,
,
,
,
,
,
,
,
,
,
,
,
,
,
,
,
,
,
,
,
,
,
,
,
,
,
,
,
,
,
,
,
,
,
,
,
,
,
,
,
,
,
,
,
,
,
,
,
,
,
,
,
,
,
,
,
,
,
,
,
,
,
,
,
,
,
,
,
,
,
,
,
,
,
,
,
,
,
,
,
,
,
,
,
,
,
,
};
int main()
{ int n;
while(scanf("%d",&n)!=EOF){
if(n==)
break;
printf("%I64d\n",a[n-]);
}
return ;
}

I

 #include <cstdio>
#include <cmath>
#include <string>
#include <cstring>
#include <algorithm>
#include <queue>
#include <map>
#include <set>
#include <stack>
#include <sstream>
#include <vector>
#define PI acos(-1.0)
#define N 111111
#define M 1000000007
#define inf 1e9
#define eps 1e-8
#define dazhi 2147483647
using namespace std; typedef unsigned long long ll; ll pow(ll a,ll b,ll p){ll sum=;for(a%=p;b;a=a*a%p,b>>=)if(b&)sum=sum*a%p;return sum;}
ll phi(ll n){ll i,re=n;for(i=;i*i<=n;i++)if(n%i==){re=re/i*(i-);while(n%i==)n/=i;}if(n>)re=re/n*(n-);return re%M;}
void exgcd(ll a,ll b,ll &x,ll &y){if(!b){x=;y=;return;}exgcd(b,a%b,y,x);y-=x*(a/b);}
ll gcd(ll a,ll b){return b==?a:gcd(b,a%b);} /****************************************/ ll b[N];
int main()
{
//ll x,y,t=0;
int n,x,y,t=;
while(scanf("%d%d%d",&n,&x,&y)!=EOF){
t++;
if(n==&&x==&&y==)break;
for(int i=;i<=n;i++){
scanf("%lld",&b[i]);
}
for(int i=;i<n;i++)
scanf("%lld",&b[n+n-i]);
if(x==)y=*n-y+;
ll xiao=1e14,biao;
for(int i=y;i<=*n;i++){
//xiao=min(xiao,b[i]);
if(b[i]<xiao)xiao=b[i],biao=i;
}
for(int i=;i<y;i++){
if(b[i]<xiao)xiao=b[i],biao=i;
}
ll ans=;
if(biao<y){
for(int i=;i<=*n;i++)
b[i]-=xiao+,ans+=xiao+;
for(int i=biao;i<y;i++)
b[i]++,ans--;
}
else{
for(int i=;i<=*n;i++)
b[i]-=xiao,ans+=xiao;
for(int i=y;i<biao;i++)
b[i]--,ans++;
}
b[biao]=ans;
printf("Case %d:\n",t);
if(biao<=n){
printf("INVALID\n");
continue;
}
for(int i=;i<=n;i++){
printf("%lld ",b[i]);
}
cout<<endl;
for(int i=;i<n;i++)
{
printf("%lld ",b[n+n-i]);
}
cout<<endl;
}
}

J

 #pragma comment(linker, "/STACK:102400000,102400000")
#include <cstdio>
#include <iostream>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <cmath>
#include <cctype>
#include <map>
#include <set>
#include <queue>
#include <bitset>
#include <string>
#include <complex>
using namespace std;
typedef pair<int,int> Pii;
typedef long long LL;
typedef unsigned long long ULL;
typedef double DBL;
typedef long double LDBL;
#define MST(a,b) memset(a,b,sizeof(a))
#define CLR(a) MST(a,0)
#define SQR(a) ((a)*(a))
#define PCUT puts("\n----------") const int maxn=+;
const DBL eps=1e-;
int sgn(DBL x){return x>eps? : (x<-eps? -: );}
struct Vector
{
DBL x,y;
Vector(DBL _x=, DBL _y=):x(_x),y(_y){}
Vector operator + (const Vector &rhs) const {return Vector(x+rhs.x, y+rhs.y);}
Vector operator - (const Vector &rhs) const {return Vector(x-rhs.x, y-rhs.y);}
Vector operator * (const DBL &rhs) const {return Vector(x*rhs, y*rhs);}
Vector operator / (const DBL &rhs) const {return Vector(x/rhs, y/rhs);}
DBL operator * (const Vector &rhs) const {return x*rhs.x + y*rhs.y;}
DBL operator ^ (const Vector &rhs) const {return x*rhs.y - rhs.x*y;}
int read(){return scanf("%lf%lf", &x, &y);}
};
typedef Vector Point; struct Line
{
Point u,v;
Line(){}
Line(Point _u,Point _v):u(_u),v(_v){}
};
int N,M;
Point A[maxn], B[maxn];
DBL Area(int,Point*);
DBL CPIA(Point*,Point*,int,int);
DBL SPIA(Point*,Point*,int,int); int main()
{
int t;
scanf("%d",&t);
for(int p=;p<=t;p++){
scanf("%d%d", &N, &M);
for(int i=; i<N; i++) A[i].read();;
for(int i=; i<M; i++) B[i].read();
printf("%.4f\n",SPIA(A,B,N,M));
}
return ;
} DBL Area(int siz, Point p[])
{
DBL res=;
for(int i=; i<siz; i++) res += (p[i-]^p[i]);
res += (p[siz-]^p[]);
return abs(res*0.5);
} Point GetLineIntSec(Line l1, Line l2)
{
DBL a = (l1.v-l1.u)^(l2.u-l1.u), b = (l1.u-l1.v)^(l2.v-l1.v);
if(sgn(a+b)==) return Point(1e9,1e9);
return Point((l2.u.x * b + l2.v.x * a) / (a + b), (l2.u.y * b + l2.v.y * a) / (a + b));
} DBL CPIA(Point a[], Point b[], int na, int nb)
{
Point p[], tmp[]; // na,nb <=20
int i, j, tn, sflag, eflag;
a[na] = a[], b[nb] = b[];
memcpy(p,b,sizeof(Point)*(nb + ));
for(i = ; i < na && nb > ; i++)
{
sflag = sgn((a[i+]-a[i])^(p[]-a[i]));
for(j = tn = ; j < nb; j++, sflag = eflag)
{
if(sflag>=) tmp[tn++] = p[j];
eflag = sgn( (a[i + ]-a[i])^(p[j + ]-a[i]));
if((sflag ^ eflag) == -)
tmp[tn++] = GetLineIntSec( Line(a[i], a[i + ]) , Line(p[j], p[j + ]));
}
memcpy(p, tmp, sizeof(Point) * tn);
nb = tn, p[nb] = p[];
}
if(nb < ) return 0.0;
return Area(nb, p);
} DBL SPIA(Point a[], Point b[], int na, int nb)
{
int i, j;
Point t1[], t2[];
double res = , num1, num2;
a[na] = t1[] = a[], b[nb] = t2[] = b[];
for(i = ; i < na; i++)
{
t1[] = a[i-], t1[] = a[i];
num1 = sgn( (t1[]-t1[])^(t1[]-t1[]));
if(num1 < ) swap(t1[], t1[]);
for(j = ; j < nb; j++)
{
t2[] = b[j - ], t2[] = b[j];
num2 = sgn((t2[]-t2[])^(t2[]-t2[]));
if(num2 < ) swap(t2[], t2[]);
res += CPIA(t1, t2, , ) * num1 * num2;
}
}
return res;
}

codeforces gym 100952 A B C D E F G H I J的更多相关文章

  1. Gym 101606 - A/B/C/D/E/F/G/H/I/J/K/L - (Undone)

    链接:https://codeforces.com/gym/101606 A - Alien Sunset 暴力枚举小时即可. #include<bits/stdc++.h> using ...

  2. Codeforces Gym 102392F Game on a Tree (SEERC2019 F题) 题解

    题目链接:https://codeforces.com/gym/102392/problem/F 题意:被这题题意坑了很久,大意是说有一棵根为 \(1\) 的树,每个节点初始都是白色, \(Alice ...

  3. codeforces gym101243 A C D E F G H J

    gym101243 A #include<iostream> #include<cstdio> #include<cmath> #include<cstrin ...

  4. Codeforces 1214 F G H 补题记录

    翻开以前打的 #583,水平不够场上只过了五题.最近来补一下题,来记录我sb的调试过程. 估计我这个水平现场也过不了,因为前面的题已经zz调了好久-- F:就是给你环上一些点,两两配对求距离最小值. ...

  5. Gym 100952 D. Time to go back(杨辉三角形)

    D - Time to go back Gym - 100952D http://codeforces.com/gym/100952/problem/D D. Time to go back time ...

  6. Gym 100952 H. Special Palindrome

    http://codeforces.com/gym/100952/problem/H H. Special Palindrome time limit per test 1 second memory ...

  7. Gym 100952 G. The jar of divisors

    http://codeforces.com/gym/100952/problem/G G. The jar of divisors time limit per test 2 seconds memo ...

  8. Gym 100952 F. Contestants Ranking

    http://codeforces.com/gym/100952/problem/F F. Contestants Ranking time limit per test 1 second memor ...

  9. Gym 100952 D. Time to go back

    http://codeforces.com/gym/100952/problem/D D. Time to go back time limit per test 1 second memory li ...

随机推荐

  1. 解决Sublime Text 3中文显示乱码(tab中文方块)问题

    博客分类:  Sublime   一.文本出现中文乱码问题 1.打开Sublime Text 3,按Ctrl+-打开控制行,复制粘贴以下python代码,然后回车运行. 2. 复制并粘贴如下代码: P ...

  2. 小白初识 - 基数排序(RadixSort)

    基数排序算是桶排序和计数排序的衍生吧,因为基数排序里面会用到这两种其中一种. 基数排序针对的待排序元素是要有高低位之分的,比如单词adobe,activiti,activiti就高于adobe,这个是 ...

  3. 小白初识 - 快速排序(QuickSort)

    我个人觉得快速排序和归并排序有相似之处,都是用到了分治的思想,将大问题拆分成若干个小问题. 不同的地方是归并排序是先把大问题拆分好了之后再排序,而快速排序则是一边拆分,一边排序. 快速排序的原理就是, ...

  4. Windows单机配置Kafka环境

    首先确保机器已经安装好Zookeeper,Zookeeper安装参考 Windows单机配置Zookeeper环境 然后确保Zookeeper是正常启动状态 下载Kafka http://kafka. ...

  5. 2019CSUST集训队选拔赛题解(一)

    来自ppq的毒瘤线段树 Sneakers   Description 有一天喜欢买鞋的ppq和小伙伴来到了某一家球鞋店,球鞋店有n种球鞋,价格分别为ai,ppq在鞋店兜兜转转,发现鞋店老板会偶尔将某段 ...

  6. sqlserver-查阻塞

    模拟阻塞: 打开两个窗口:     窗口一: BEGIN TRANSACTION--开始事务 --等待1分钟 WAITFOR DELAY '00:1'; 窗口二: 查询阻塞:(当前被阻塞的进程id,不 ...

  7. Polycarp and Letters(set首战!)

    Description Polycarp loves lowercase letters and dislikes uppercase ones. Once he got a string s con ...

  8. 王者荣耀交流协会--第2次Scrum会议

    Scrum master:袁玥 要求1:工作照片 要求2:时间跨度:2017年10月14号  6:02--6:43  共计41min 要求3:地点:一食堂二楼两张桌子旁(靠近卖方便面那边) 要求4:立 ...

  9. pspo过程文档

    项目计划总结:       日期/任务      听课        编写程序         阅读相关书籍 日总计          周一      110          60         ...

  10. 第一次c++作业(感觉不是很好系列)

    日常先贴github的地址 https://github.com/egoistor/Elevator-scheduling 然后我觉得学习了半天,构造函数似懂非懂(用的是class自动生成的构造函数, ...