# 第七届福建省程序设计竞赛题解

#include <iostream>
#include <stdio.h>
#include <string.h>
#include <algorithm>
#include <cmath>

using namespace std;
int a[11111];
int b[11111];
int main()
{
int T;
scanf("%d",&T);
int cas=0;
while(T--){
int n;
scanf("%d",&n);
for(int i=1;i<=n;i++){
scanf("%d",&a[i]);
}
for(int i=1;i<=n;i++){
scanf("%d",&b[i]);
}
// cout<<a[1]<<b[1]<<endl;
sort(a+1,a+1+n);sort(b+1,b+1+n);
int tmp1=0,tmp2=0;
for(int i=1;i<=n;i++){
int cs=lower_bound(b+1,b+1+n,a[i])-b-1;
tmp1+=cs;
}
// cout<<tmp1<<endl;
double ans=1.0*tmp1/n;
printf("Case %d: %.2lf\n",++cas,ans);
}

return 0;
}

C.Bond
D.The Bigger the Better

#include<iostream>
#include<cstring>
#include<cstdio>
#include<algorithm>
#include<string>
#include<map>
#include<queue>
#include<vector>
using namespace std;
#define ll long long int
#define INF 0x3f3f3f3f
#define Irish_Moonshine main
const int maxn = 2e5 + 2333;
int a[maxn];
int b[maxn];
int ans[maxn];

int Irish_Moonshine()
{
int T; int cs = 0;
scanf("%d", &T);
while (T--) {
int n, m;
scanf("%d%d", &n, &m);
memset(a,0,sizeof a);
memset(b,0,sizeof b);
//cout << n << endl << m << endl;
for (int i = 0; i < n; i++) scanf("%d", &a[i]);
for (int i = 0; i < m; i++) scanf("%d", &b[i]);
int pos1 = 0, pos2 = 0, cnt = 0;
while (pos1 < n&&pos2 < m) {
if (a[pos1] > b[pos2]) ans[cnt++] = a[pos1++];
else if (a[pos1] < b[pos2]) ans[cnt++]=b[pos2++];
else {
int f = memcmp(a + pos1, b + pos2, sizeof a);
if (f < 0) {
while (a[pos1] == b[pos2] && pos1 < n&&pos2 < m) ans[cnt++] = b[pos2++];
}
else {
while (a[pos1] == b[pos2] && pos1 < n&&pos2 < m) ans[cnt++] = a[pos1++];
}
}
}
while (pos1 < n) ans[cnt++] = a[pos1++];
while (pos2 < m) ans[cnt++] = b[pos2++];
printf("Case %d: ", ++cs);
for (int i = 0; i < cnt; i++) {
printf("%d", ans[i]);
}
printf("\n");
}
return 0;
}

E.Card Game(First Edition)

#include <iostream>
#include <stdio.h>
#include <string.h>
#include <algorithm>
#include <cmath>

using namespace std;

int main()
{
int T;
scanf("%d",&T);
int cas=0;
while(T--){
int n;
scanf("%d",&n);
for(int i=1;i<=2*n;i++){
int x;
scanf("%d",&x);
}
printf("Case %d: %.2lf\n",++cas,1.0*n/2);
}

return 0;
}

F.Card Game(Third Edition}

#include <iostream>
#include <stdio.h>
#include <string.h>
#include <algorithm>
#include <cmath>

using namespace std;
int a[11111];
int b[11111];
int main()
{
int T;
scanf("%d",&T);
int cas=0;
while(T--){
int n;
scanf("%d",&n);
for(int i=1;i<=n;i++)
scanf("%d",&a[i]);
for(int i=1;i<=n;i++)
scanf("%d",&b[i]);
int ans = 0;
for(int i=1;i<=n;i++){
if(a[i]+b[i]>10)
ans++;
}
printf("Case %d: %d\n",++cas,ans);
}

return 0;
}

G.Cutting Game

#include <iostream>
#include <stdio.h>
#include <string.h>
#include <algorithm>
#include <cmath>

using namespace std;

int main()
{
int T;
scanf("%d",&T);
int cas=0;
while(T--){
int n;
scanf("%d",&n);int tmp=1;int ans;
for(int i=1;i<=n;i++)
{
tmp*=2;
if(tmp-1>=n){
ans=i;
break;
}
}
printf("Case %d: %d\n",++cas,ans);
}

return 0;
}

H.Picking Game
I.Two Triangles

#include<iostream>
#include<cstring>
#include<cstdio>
#include<algorithm>
#include<string>
#include<map>
#include<queue>
#include<vector>
using namespace std;
#define ll long long int
#define INF 0x3f3f3f3f
int x[20], y[20];
int n, T, ans, cnt, num;
int vis[20];
int len(int a, int b) {
return (x[a] - x[b])*(x[a] - x[b]) + (y[a] - y[b])*(y[a] - y[b]);
}
bool check(int &a, int &b, int &c) {
int x1 = x[b] - x[a];
int y1 = y[b] - y[a];
int x2 = x[c] - x[b];
int y2 = y[c] - y[b];
int l1, l2, l3;
l1 = l2 = l3 = 0;
int tmp = y2 * x1 - x2 * y1;
if (tmp > 0) {
l1 = len(a, b);
l2 = len(b, c);
l3 = len(c, a);
}
else if (tmp < 0) {
l1 = len(a, c);
l2 = len(c, b);
l3 = len(b, a);
}
else return 0;
a = l1;
b = l2;
c = l3;
return 1;
}
void slove(int a, int b, int c) {
int l1 = a, l2 = b, l3 = c;
if (!check(l1, l2, l3)) return;
for (int i = a + 1; i <= n - 2; i++) {
if (vis[i]) continue;
for (int j = i + 1; j <= n - 1; j++) {
if (vis[j]) continue;
for (int k = j + 1; k <= n; k++) {
if (vis[k]) continue;
int L1 = i, L2 = j, L3 = k;
if (!check(L1, L2, L3)) continue;
if (L1 == l1 && L2 == l2 && L3 == l3) ans++;
else if (L1 == l2 && L2 == l3 && L3 == l1) ans++;
else if (L1 == l3 && L2 == l1 && L3 == l2) ans++;
}
}
}
}
int main()
{
//int T;
int cs = 0;
scanf("%d", &T);
while (T--) {
ans = 0; cnt = 0; num = 0;
memset(vis, 0, sizeof vis);
scanf("%d", &n);
for (int i = 1; i <= n; i++) {
scanf("%d%d", &x[i], &y[i]);
}
ans = 0;
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++) {
vis[i] = vis[j] = vis[k] = 1;
slove(i, j, k);
vis[i] = vis[j] = vis[k] = 0;
}
}
}
printf("Case %d: %d\n", ++cs, 2 * ans);
}
return 0;
}
//_CRT_SECURE_NO_WARNINGS

J.X

#include <iostream>
#include <stdio.h>
#include <string.h>
#include <algorithm>
using namespace std;
const int inf = 0x3f3f3f3f;
int mp[111][111];
int used[111][111];
int n,m;

void floyd()
{
for(int k=1;k<=n;k++){
for(int i=1;i<=n;i++){
if(mp[i][k]!=inf){
for(int j=1;j<=n;j++){
if(mp[i][k]+mp[k][j]<=mp[i][j])
mp[i][j]=mp[i][k]+mp[k][j],used[i][j]=used[j][i] = 1;

}
}
}
}
}

struct node
{
int u,v,w;
}len[40200];

int xmp[111][111];

int main()
{
int T;
scanf("%d",&T);
int cas=0;
while(T--){
scanf("%d %d",&n,&m);
for(int i=1;i<=n;i++){
for(int j=1;j<=n;j++){
mp[i][j]=inf;
xmp[i][j]=inf;
used[i][j]=0;
}
}
int now = 0;
for(int i=1;i<=m;i++){
int u,v,w;
scanf("%d%d%d",&u,&v,&w);
if(mp[u][v]!=inf) now++;
if(mp[u][v]>w){
mp[u][v]=mp[v][u]=w;
xmp[u][v]=xmp[v][u]=w;
}
}

int cnt = 0;
/*    for(int i=1;i<=n;i++){
for(int j=i+1;j<=n;j++){
if(mp[i][j]!=inf){
len[++cnt].u=i;
len[cnt].v=j;
len[cnt].w=mp[i][j];
}
}
}*/
floyd();
int ans=0;
/*   for(int i=1;i<=cnt;i++){
if(mp[len[i].u][len[i].v]==len[i].w)
ans++;
}*/
for(int i=1;i<=n;i++)
for(int j=i+1;j<=n;j++)
if(used[i][j]==1&&xmp[i][j]!=inf)
ans++;
printf("Case %d: %d\n",++cas,ans+now);

}

return 0;
}