A.足球!足球!足球!{target=”_blank”}
#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <string>
#include <cmath>
#include <map>
#include <queue>
using namespace std;
typedef long long LL;
typedef pair<int, int> PII;
const int N = 2e5 + 10;
struct node
{
int point;
int jing;
int sum;
} p[10];
int main()
{
int T;
cin >> T;
while (T--)
{
memset(p, 0, sizeof p);
char a, b;
int x1, y1, x2, y2;
for (int i = 1; i <= 15; i++)
{
cin >> a >> b >> x1 >> y1 >> x2 >> y2;
if (x1 < y1)
p[b - 'A'].point += 3;
else if (x1 == y1)
p[a - 'A'].point++, p[b - 'A'].point++;
else
p[a - 'A'].point += 3;
if (x2 < y2)
p[b - 'A'].point += 3;
else if (x2 == y2)
p[a - 'A'].point++, p[b - 'A'].point++;
else
p[a - 'A'].point += 3;
p[a - 'A'].jing += x1 + x2 - y1 - y2;
p[b - 'A'].jing += y1 + y2 - x1 - x2;
p[a - 'A'].sum += x1 + x2;
p[b - 'A'].sum += y1 + y2;
}
for (int i = 0; i < 6; i++)
cout << p[i].point << ' ' << p[i].jing << ' ' << p[i].sum << endl;
}
return 0;
}
B.ACM排座位{target=”_blank”}
法一:
#include <iostream>
#include <algorithm>
#include <cstring>
#include <cmath>
#include <string>
using namespace std;
const int N = 110;
int n, d;
int ans[N];
int main()
{
while (cin >> n >> d)
{
bool flag = true;
if (d >= n / 2)
{
puts("-1");
flag = false;
}
if (flag)
{
int i = 0, t = 1;
while (i < n)
{
ans[i++] = n / 2 + t;
ans[i++] = t;
t++;
}
for (int i = 0; i < n; i++)
printf(i == n - 1 ? "%d\n" : "%d ", ans[i]);
}
}
return 0;
}
法二:
#include <iostream>
#include <algorithm>
#include <cstring>
#include <cmath>
#include <string>
using namespace std;
const int N = 110;
int n, d;
int group[N][N];
int pos[N], cnt;
bool vis[N];
int ans[N];
int main()
{
while (cin >> n >> d)
{
memset(pos, 0, sizeof pos);
memset(vis, false, sizeof vis);
cnt = 0;
for (int i = 1; i <= n; i++)
{
if (vis[i])
continue;
cnt++;
for (int j = i; j <= n; j += d + 1)
{
vis[j] = true;
group[cnt][pos[cnt]++] = j;
}
}
int k = 0;
for (int i = cnt; i; i--)
{
for (int j = 0; j < pos[i]; j++)
ans[k++] = group[i][j];
}
bool flag = true;
for (int i = 0; i < n - 1; i++)
if (abs(ans[i] - ans[i + 1]) <= d)
{
flag = false;
break;
}
if (!flag)
puts("-1");
else
for (int i = 0; i < n; i++)
printf(i == n - 1 ? "%d\n" : "%d ", ans[i]);
}
return 0;
}
C.白学长想电脑开机啊!!!{target=”_blank”}
#include <iostream>
#include <algorithm>
#include <cstring>
#include <cmath>
#include <string>
using namespace std;
const int N = 1010;
int n;
int main()
{
int T;
cin >> T;
while (T--)
{
cin >> n;
if (n % 3 == 1)
cout << 1;
for (int i = 1; i <= n / 3; i++)
cout << 21;
if (n % 3 == 2)
cout << 2;
cout << endl;
}
return 0;
}
D.假期卷王is me.{target=”_blank”}
#include <iostream>
#include <algorithm>
#include <cstring>
#include <cmath>
#include <string>
#include <map>
#include <queue>
#include <vector>
#include <functional>
using namespace std;
const int N = 1010;
int g[N][N];
bool vis[N];
int dist[N];
int n, m;
void dijkstra()
{
memset(dist, 0x3f, sizeof dist);
memset(vis, false, sizeof vis);
dist[1] = 0;
for (int i = 0; i < n; i++)
{
int t = -1;
for (int j = 1; j <= n; j++)
if (!vis[j] && (t == -1 || dist[j] < dist[t]))
t = j;
vis[t] = true;
for (int j = 1; j <= n; j++)
dist[j] = min(dist[j], dist[t] + g[t][j]);
}
}
int main()
{
cin >> m >> n;
memset(g, 0x3f, sizeof g);
while (m--)
{
int a, b, c;
cin >> a >> b >> c;
g[a][b] = g[b][a] = min(g[a][b], c);
}
dijkstra();
cout << dist[n] << endl;
return 0;
}
E.奇怪的走路要求{target=”_blank”}
#include <iostream>
#include <cstring>
#include <algorithm>
#include <cmath>
using namespace std;
const int N = 1010;
int main()
{
int T;
cin >> T;
while (T --){
int x, y;
cin >> x >> y;
if (!x && !y)
puts("0");
else{
int z = x * x + y * y;
if (sqrt(z) == floor(sqrt(z)))
puts("1");
else
puts("2");
}
}
return 0;
}
F.生日快乐{target=”_blank”}
#include <iostream>
#include <algorithm>
#include <cstring>
#include <cmath>
#include <string>
using namespace std;
const int N = 1010;
int n;
int a[N];
int main()
{
int T;
cin >> T;
while (T--)
{
cin >> n;
for (int i = 0; i < n; i++)
cin >> a[i];
sort(a, a + n);
cout << a[n - 1] + a[n - 2] << endl;
}
return 0;
}
G.用魔法打败魔法{target=”_blank”}
#include <iostream>
#include <algorithm>
#include <cstring>
#include <cmath>
#include <string>
#include <map>
#include <queue>
#include <vector>
#include <set>
#include <functional>
using namespace std;
const int N = 100010;
int fa[30], h[30];
string a, b;
int n;
void Init()
{
for (int i = 0; i < 30; i++)
fa[i] = i;
}
int find(int x)
{
if (fa[x] != x)
fa[x] = find(fa[x]);
return fa[x];
}
int main()
{
Init();
scanf("%d", &n);
cin >> a >> b;
if (a == b)
{
puts("0");
return 0;
}
int res = 0;
for (int i = 0; i < a.size(); i++)
if (a[i] != b[i])
{
int x = a[i] - 'a' + 1;
int y = b[i] - 'a' + 1;
int fx = find(x), fy = find(y);
if (fx != fy)
{
fa[fx] = fy;
res++;
}
}
printf("%d\n", res);
return 0;
}
H.“简单”的最短路{target=”_blank”}
#include <iostream>
#include <algorithm>
#include <cstring>
#include <cmath>
#include <string>
using namespace std;
const int N = 1010;
int n, m, casei;
int g[N][N];
bool vis[N];
int dist[N];
void dijkstra()
{
int ver;
for (int i = 1; i <= n; i++)
dist[i] = g[1][i];
memset(vis, false, sizeof vis);
for (int i = 0; i < n; i++)
{
int t = -1;
for (int j = 1; j <= n; j++)
if (!vis[j] && dist[j] > t)
{
t = dist[j];
ver = j;
}
vis[ver] = true;
for (int j = 1; j <= n; j++)
if (!vis[j] && dist[j] < min(dist[ver], g[ver][j]))
dist[j] = min(dist[ver], g[ver][j]);
}
}
int main()
{
int T;
scanf("%d", &T);
while (T--)
{
memset(g, 0, sizeof g);
scanf("%d%d", &n, &m);
while (m--)
{
int a, b, c;
scanf("%d%d%d", &a, &b, &c);
g[a][b] = g[b][a] = c;
}
dijkstra();
printf("Scenario #%d:\n", ++casei);
printf("%d\n", dist[n]);
puts("");
}
return 0;
}
I.盘子排列{target=”_blank”}
#include <iostream>
#include <algorithm>
#include <cstring>
#include <cmath>
#include <string>
#include <map>
#include <queue>
#include <vector>
#include <functional>
using namespace std;
const int N = 1010;
map<char, int> mp;
vector<int> v;
int g[10][10];
int in[10];
char arr[] = {'A', 'B', 'C', 'D', 'E'};
void topsort()
{
priority_queue<int, vector<int>, greater<int>> heap;
for (int i = 0; i < 5; i++)
if (!in[i])
heap.push(i);
while (!heap.empty())
{
int t = heap.top();
heap.pop();
v.push_back(t);
for (int i = 0; i < 5; i++)
{
if (g[t][i])
{
in[i]--;
if (!in[i])
heap.push(i);
}
}
}
}
int main()
{
mp['A'] = 0;
mp['B'] = 1;
mp['C'] = 2;
mp['D'] = 3;
mp['E'] = 4;
for (int i = 1; i <= 5; i++)
{
string x;
cin >> x;
if (x[1] == '>')
swap(x[0], x[2]);
in[mp[x[0]]]++;
g[mp[x[2]]][mp[x[0]]] = 1;
}
topsort();
if (v.size() < 5)
puts("impossible");
else
{
for (int i = 4; i >= 0; i--)
cout << arr[v[i]];
cout << endl;
}
return 0;
}
J.郭学长的调查{target=”_blank”}
#include <iostream>
#include <algorithm>
#include <cstring>
#include <cmath>
#include <string>
#include <map>
#include <queue>
#include <vector>
#include <functional>
using namespace std;
const int N = 50010;
int fa[N];
int n, m, casei;
int find(int x)
{
if (fa[x] != x)
fa[x] = find(fa[x]);
return fa[x];
}
void merge(int x, int y)
{
int fx = find(x), fy = find(y);
if (fx != fy)
fa[fx] = fy;
}
int main()
{
while (cin >> n >> m)
{
if (!n && !m)
break;
for (int i = 1; i <= n; i++)
fa[i] = i;
while (m--)
{
int a, b;
cin >> a >> b;
merge(a, b);
}
int res = 0;
for (int i = 1; i <= n; i++)
if (fa[i] == i)
res++;
printf("Case %d: ", ++casei);
cout << res << endl;
}
return 0;
}
%%
tql%%
tql