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. Update类型_JDBC的方法_JAVA方法_Loadrunner脚本

    java vuser   JDBC 参数化的方法 如果不进行参数化 直接把32  33行去掉 ,sql 值写到valuers  中就行了 下面这是 insert,delete,update  三种方法 ...

  2. Gradle初使用

    我以前一直使用Maven来构建工程,这两天突然发现gradle也非常好用,记录一下自己使用gradle的过程. Gradle的下载与配置 本次选择下载的是gradle3.5版本,没选最新的gradle ...

  3. Bracket Sequences Concatenation Problem括号序列拼接问题(栈+map+思维)

    A bracket(括号) sequence is a string containing only characters "(" and ")".A regu ...

  4. 吴恩达机器学习笔记——正规方程(Normal Equation)

    问题描述:m examples : (x(1),y(1)), (x(2),y(2)),..., (x(m),y(m)) and n features; 计算方法:θ = (XTX)-1XTy; 计算过 ...

  5. SpringMVC相关的面试题

    1.什么是springMVC springmvc是spirng框架的一个模块,是一个基于MVC框架的web框架 2.springmvc的流程 a.客户端发送请求 b.前端控制器DispatcherSe ...

  6. 404 Note Found 现场编程

    目录 组员职责分工 github 的提交日志截图 程序运行截图 程序运行环境 GUI界面 基础功能实现 运行视频 LCG算法 过滤(降权)算法 算法思路 红黑树 附加功能一 背景 实现 附加功能二(迭 ...

  7. oracle与DB2的一些架构

    首先,我们需要理解 Oracle 使用的架构,并理解它与 DB2 的不同之处.图 1 展示了 Oracle 的系统结构.将该图与 图 2 进行比较,后者显示了 DB2 的系统结构.在阅读本文的时候,为 ...

  8. WCF RestFull提交数据超出限额解决方法

    最近在使用wcf restfull时出现了超大数据提交出错的问题. 服务端会返回错误:服务器处理请求时遇到错误.有关构造有效服务请求的内容,请参阅服务帮助页.异常消息为“反序列化对象 属于类型 Yes ...

  9. beta阶段——项目复审

    beta阶段--项目复审 小组的名字和链接 优点 缺点 bug 排名顺序 颜罗王team http://www.cnblogs.com/LDLYMteam 界面清新,音乐能够选择是否播放,词汇按照四六 ...

  10. phpcms前端模板目录与文件结构分析图【templates】

    phpcms前端模板目录与文件结构分析图[templates] 原文地址:http://www.iphpcms.net/phpcms-ziliao/2015_14.html