2262 Best Friend Forever

————————————————————————————————————————————

2263 Bond

————————————————————————————————————————————

2264 Card Game (First Edition)

————————————————————————————————————————————

LL a[N];

int main(){
int _=read(),kcase=0;
while(_--){
int n=read()*2;
for(int i=1;i<=n;i++) scanf("%lld",&a[i]);

sort(a+1,a+n+1);

LL ans = 0;
for(int i=1;i<=n;i++){
int l=1,r=n,mid,tmp=0;
while(l<=r){//puts("---");
mid = r+l >> 1;
if(a[mid]<a[i]) tmp = mid,l = mid+1;
else  r = mid-1;
}
ans+=tmp;
}
//        printf("%lld/%lld\n",ans,(LL)(2*n-2));
double aaa = ans*1.0/(2.0*n-2.0);
printf("Case %d: %.2f\n",++kcase,aaa);

}
return 0;
}

2265 Card Game (Second Edition)

————————————————————————————————————————————

ni=1nj=1[ai>bj]×C(n,1)×(n1)!×(n1)!n!×n!=ni=1nj=1[ai>bj]n

LL a[N],b[N];

int main(){
int _=read(),kcase=0;
while(_--){
int n=read();
for(int i=1;i<=n;i++) scanf("%lld",&a[i]);
for(int i=1;i<=n;i++) scanf("%lld",&b[i]);
sort(b+1,b+n+1);

LL ans = 0;
for(int i=1;i<=n;i++){
int l=1,r=n,mid,tmp=0;
while(l<=r){//puts("---");
mid = r+l >> 1;
if(b[mid]<a[i]) tmp = mid,l = mid+1;
else  r = mid-1;
}
ans+=tmp;
}
double aaa = ans*1.0/(1.0*n);
printf("Case %d: %.2f\n",++kcase,aaa);

}
return 0;
}

2266 Card Game (Third Edition)

————————————————————————————————————————————

2267 The Bigger the Better

————————————————————————————————————————————

//#include <bits/stdc++.h>
#include <iostream>
#include <string.h>
#include <algorithm>
#include <stdio.h>
typedef long long int LL;
using namespace std;

const int N   = 2e5+7;
const int MOD = 1e9+7;

/********************************************/

int n,m;

const int MAXN=400010;
//以下为倍增算法求后缀数组
int wa[MAXN],wb[MAXN],wv[MAXN],Ws[MAXN];
int cmp(int *r,int a,int b,int l) {
return r[a]==r[b]&&r[a+l]==r[b+l];
}
/**< 传入参数：str,sa,len+1,ASCII_MAX+1 */
void da(const int r[],int sa[],int n,int m) {
int i,j,p,*x=wa,*y=wb,*t;
for(i=0; i<m; i++) Ws[i]=0;
for(i=0; i<n; i++) Ws[x[i]=r[i]]++;//以字符的ascii码为下标
for(i=1; i<m; i++) Ws[i]+=Ws[i-1];
for(i=n-1; i>=0; i--) sa[--Ws[x[i]]]=i;
/*cout<<"SA"<<endl;;
for(int i=0;i<n+1;i++)cout<<sa[i]<<' ';*/
for(j=1,p=1; p<n; j*=2,m=p) {
for(p=0,i=n-j; i<n; i++) y[p++]=i;
for(i=0; i<n; i++) if(sa[i]>=j) y[p++]=sa[i]-j;
for(i=0; i<n; i++) wv[i]=x[y[i]];
for(i=0; i<m; i++) Ws[i]=0;
for(i=0; i<n; i++) Ws[wv[i]]++;
for(i=1; i<m; i++) Ws[i]+=Ws[i-1];
for(i=n-1; i>=0; i--) sa[--Ws[wv[i]]]=y[i];
for(t=x,x=y,y=t,p=1,x[sa[0]]=0,i=1; i<n; i++)
x[sa[i]]=cmp(y,sa[i-1],sa[i],j)?p-1:p++;
}
return;
}
int sa[MAXN],Rank[MAXN],height[MAXN];
//求height数组
/**< str,sa,len */
void calheight(const char *r,int *sa,int n) {
int i,j,k=0;
for(i=1; i<=n; i++) Rank[sa[i]]=i;
for(i=0; i<n; height[Rank[i++]]=k)
for(k?k--:0,j=sa[Rank[i]-1]; r[i+k]==r[j+k]; k++);
// Unified
for(int i=n; i>=1; --i) ++sa[i],Rank[i]=Rank[i-1];
}

int a[N*2];

int main() {
int _ ,kcase = 0;
scanf("%d",&_);
while(_--) {
scanf("%d%d",&n,&m);
for(int i=0; i<n; i++) scanf("%d",&a[i]);
a[n]=0;
for(int i=0; i<m; i++) scanf("%d",&a[i+n+1]);

da(a,sa,n+m+1,101);
for(int i=0;i<n+m+1;i++) Rank[sa[i]]=i;

int la=0,lb=n+1;
printf("Case %d: ",++kcase);
while(la<n&&lb<n+m+1){
if(a[la]>a[lb])            printf("%d",a[la++]);
else if(a[la]<a[lb])       printf("%d",a[lb++]);
else if(Rank[la]>Rank[lb]) printf("%d",a[la++]);
else                       printf("%d",a[lb++]);
}
while(la<n) printf("%d",a[la++]);
while(lb<n+m+1) printf("%d",a[lb++]);
puts("");
}
return 0;
}
/**
44
4 4
1 1 9 5
1 1 9 8

4 4
1 1 9 8
1 1 9 5

8 7
5 5 9 8 5 5 9 8
5 5 9 5 5 9 5

7 8
5 5 9 5 5 9 5
5 5 9 8 5 5 9 8

8 7
5 5 9 8 5 5 9 5
5 5 9 5 5 9 8

7 8
5 5 9 5 5 9 8
5 5 9 8 5 5 9 5

2 3
3 2
3 4 7

3 2
3 4 7
3 2

3 4
3 3 2
3 3 4 7

4 3
3 3 4 7
3 3 2

6 6
3 3 4 4 7 9
3 3 4 4 7 9

3 3
1 2 2
2 1 2

1 1
1
1

5 10
5 6 7 8 9
1 5 6 7 8 5 6 7 9 9

4 3
1 3 2 4
4 1 3

3 3
4 4 3
4 2 3

3 3
4 2 3
4 4 3

3 3
4 4 6
4 2 6

3 3
4 2 6
4 4 6

7 7
7 1 9 1 7 1 9
7 1 9 1 8 7 1

7 7
7 1 1 9 7 1 9
7 1 9 1 1 8 7

----------------------

Case 1: 11981195
Case 2: 11981195
Case 3: 559855985595595
Case 4: 559855985595595
Case 5: 559855955985595
Case 6: 559855955985595
Case 7: 34732
Case 8: 34732
Case 9: 3347332
Case 10: 3347332
Case 11: 334479334479
Case 12: 212212
Case 13: 11
Case 14: 567891567856799
Case 15: 4132413
Case 16: 444323
Case 17: 444323
Case 18: 446426
Case 19: 446426
Case 20: 77191918717191
Case 21: 77191197191187
*/


2268 Cutting Game

————————————————————————————————————————————

2269 Picking Game

————————————————————————————————————————————

2270 Two Triangles

————————————————————————————————————————————

int n,ans;
struct point{
int x,y;
}p[100];

int dis(int p1,int p2){
return (p[p1].x-p[p2].x)*(p[p1].x-p[p2].x)+(p[p1].y-p[p2].y)*(p[p1].y-p[p2].y);
}

int mul(int p1,int p2,int p0){
return ((p[p1].x-p[p0].x)*(p[p2].y-p[p0].y)-(p[p2].x-p[p0].x)*(p[p1].y-p[p0].y));
}

int judge(int s1p1,int s1p2,int s1p3,int s2p1,int s2p2,int s2p3){
if(mul(s1p2,s1p3,s1p1)<0) swap(s1p2,s1p3);
if(mul(s2p2,s2p3,s2p1)<0) swap(s2p2,s2p3);

int s1l1 = dis(s1p1,s1p2);
int s1l2 = dis(s1p2,s1p3);
int s1l3 = dis(s1p1,s1p3);

int s2l1 = dis(s2p1,s2p2);
int s2l2 = dis(s2p2,s2p3);
int s2l3 = dis(s2p1,s2p3);

if(s1l1 == s2l1 &&s1l2 == s2l2 &&s1l3 == s2l3 )  return 1;
if(s1l1 == s2l2 &&s1l2 == s2l3 &&s1l3 == s2l1 )  return 1;
if(s1l1 == s2l3 &&s1l2 == s2l1 &&s1l3 == s2l2 )  return 1;

return 0;
}
double l[4];
void solve(int p1,int p2,int p3){

l[1] = sqrt(1.0*dis(p1,p2));
l[2] = sqrt(1.0*dis(p2,p3));
l[3] = sqrt(1.0*dis(p1,p3));
sort(l+1,l+4);
if(l[1]+l[2]<=l[3]+eps&&l[1]+l[2]>=l[3]-eps) return;

for(int i=1;i<=n-2;++i){
if(i==p1||i==p2||i==p3) continue;
for(int j=i+1;j<=n-1;++j){
if(j==p1||j==p2||j==p3) continue;
for(int k=j+1;k<=n;++k){
if(k==p1||k==p2||k==p3) continue;
if(judge(p1,p2,p3,i,j,k)) ans++;
}
}
}
}

int main(){
int _ = read(),kcase=0;
while(_--){
n=read(); ans = 0;
for(int i=1;i<=n;++i) scanf("%d%d",&p[i].x,&p[i].y);

for(int i=1;i<=n-2;++i)
for(int j=i+1;j<=n-1;++j)
for(int k=j+1;k<=n;++k)
solve(i,j,k);

printf("Case %d: %d\n",++kcase,ans);
}
return 0;
}

2271 X

————————————————————————————————————————————

if(floyd[i][j]>=floyd[i][k]+floyd[k][j])floyd[i][j]=floyd[i][k]+floyd[k][j];

int n,m,ans;

int mp[111][111];
int fd[111][111];
int vs[111][111];

int main(){
int _ = read(),kcase = 0;
while(_--){
n=read(),m=read(); ans = 0 ;

for(int i=1;i<=n;i++)for(int j=1;j<=n;j++){
fd[i][j]=mp[i][j]=N;vs[i][j]=0;
}

for(int i=1,x,y,w;i<=m;i++){
x=read(),y=read(),w=read();
if(mp[x][y]!=N){
ans++;
if(w<mp[x][y]){
mp[x][y]=mp[y][x]=w;
fd[x][y]=fd[y][x]=w;
}
continue;
}
mp[x][y]=mp[y][x]=w;
fd[x][y]=fd[y][x]=w;
}

for(int i=1;i<=n;i++) fd[i][i]=mp[i][i]=0;

for(int k=1;k<=n;k++)for(int i=1;i<=n;i++)for(int j=1;j<=n;j++){
if(fd[i][j]>=fd[i][k]+fd[k][j]){
fd[i][j]=fd[i][k]+fd[k][j];
if(i!=j&&i!=k&&k!=j&&mp[i][j]!=N&&!vs[i][j]){
ans++;vs[i][j]=vs[j][i]=1;
}
}
}
printf("Case %d: %d\n",++kcase,ans);
}
return 0;
}
09-19 41

05-07 26
07-18 941
05-23 2280
©️2020 CSDN 皮肤主题: 技术黑板 设计师:CSDN官方博客