有时候,很简单的模板题,可能有人没有做出来,(特指 I ),到时候一定要把所有的题目全部看一遍

B





输入样例

3 2
1 2 1
2 3 1

输出样例

1

说明

In the first sample case, the sequence [a1,a2,a3]=[0,1,0][a_1,a_2,a_3]=[0,1,0][a1,a2,a3]=[0,1,0] meets all the constraints and has the minimum sum of all the elements.

题解

这一道题目的关键就是要知道:异或操作的操作是位与位之间相互独立的,所以就可以对于每一位进行单独考虑。

如果这一位异或操作的结果是1那么就说明该这两位的取值必定相反,如果是0,那么就说明这两位的取值必定相同。

 #include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define N 100020
int n, m;
//int a[N];
int fa[N*2];
struct {
int x, y, xo;
}b[N*2]; int get(int x)
{
if(fa[x] == x) return x;
return fa[x] = get(fa[x]);
}
ll solve(int idx)//对于每一位进行操作
{
for(int i = 1; i <= 2*n; i++) fa[i] = i;
for(int i = 1; i <= m; i++)
{
int x = b[i].x;
int y = b[i].y;
int xo = ((b[i].xo)>>idx)&1;
if(xo == 1){
if(get(x) == get(y) ){
return -1;
}
else
{
fa[get(x)] = get(y+n);
fa[get(y)] = get(x+n);
}
}
else if(xo == 0)
{
if(get(x) == get(y+n) ){
return -1;
}else{
fa[get(x)] = get(y);
fa[get(y+n)] = get(x+n);
}
}
}
map<int, pair<int, int> >mp;
for(int i = 1; i <= n; i++)
{
//cout << "n:" << n << "\n";
int id = min(get(i), get(i+n));
//cout << id << " " << get(i) << "\n";
if(get(i) == id){
mp[id].first++;
}
else {
mp[id].second++;
}
}
ll ans = 0;
for(auto &x : mp)
{
ans += min(x.second.first, x.second.second);
//cout << x.first << " "<< x.second.first << " " << x.second.second << "\n";
}
return ans;
}
int main()
{
scanf("%d%d", &n, &m);
for(int i = 1; i <= m; i++)
{
scanf("%d%d%d", &b[i].x, &b[i].y, &b[i].xo);
} ll ans = 0;
for(int i = 0; i <= 30; i++)
{
ll ret;
ret = solve(i);
if(ret == -1){
puts("-1");
return 0;
}
ans += ret << i;
}
printf("%lld", ans);
system("pause");
return 0;
}

E

On November 6, 2021, the Chinese team Edward Gaming (EDG) defeated the South Korea team DWG KIA (DK) to win the 2021 League of Legends World championship in Reykjavík, Iceland, lifting the Summoner's Cup for the first time in their history.

While both teams had looked dominant(占主导地位) throughout the competition, DK arguably(可以论证的) had the advantage. The team hadn't lost a single game until they reached the semi-finals and was the only team to make it out of the Group Stage without a single defeat. They were clearly the team to beat.

EDG had given them a hit at the very first game of the final. The game started with a well-executed gank in the bot lane by EDG for the first blood. Later, EDG took every single Drake and the Baron, and ultimately destroyed the DK's Nexus after 35 minutes.

But DK wouldn't leave it unanswered. They maintained an advantage throughout the second game. Not even the incredible Baron steal by EDG's legendary jungler, Jiejie , could help the team.

The third game turned out to be a difficult one. EDG seems to have control over more resources during the first 30 minutes. However, DK constantly killed every single dragon, and they finally took down the Nexus with the Hand of Baron.

In the fourth game, EDG had rethought their approach and took higher precedence in the control over dragons. The strategy had immediately taken effect, and they won the game after 33 minutes.

All things came down to the last game of the finals. Initially, DK took up the first dragon without much resistance from EDG. Shortly after, EDG picked first blood as DK took the Herald. Everything was fairly even at that moment. The balance finally started to tip in EDG's favor during a team fight in the mid-lane, with EDG killing DK's midlaner Showmaker before they had a chance to respond. The fight finally ended up with four kills and one death for EDG. They snowballed their advantage and finally secured the trophy.

The triumph of the Worlds 2021 made EDG the first team from LPL to win both the Mid-Season Invitational and the World Championship. You have just written a long string to celebrate this great victory. How many occurrences of "edgnb" as a continuous substring are there in the long string? Please write a program to count the number.

输入描述:

The only line contains a nonempty string, which consists of no more than 200000 lowercase Latin letters, 'a' to 'z'.

输出描述:

Output a line containing a single integer, indicating the number of occurrences of "edgnb" in the given string.

edgnb
1

并没有必要阅读

#include <bits/stdc++.h>
using namespace std;
char a[300000];
int main()
{
scanf("%s", a+1);
int len = strlen(a+1);
int ans = 0;
for(int i = 1; i <= len; i++)
{
if(a[i] == 'e' && a[i+1] == 'd' && a[i+2] == 'g' && a[i+3] == 'n' && a[i+4] == 'b')
ans ++; }
cout << ans;
return 0;
}

F

输入样例1

4
aacc

输出样例1

bbaa

输入样例2

3
aca

输出样例2

ba

题解

暴力枚举

#include <bits/stdc++.h>
using namespace std;
#define N 1010
int n;
char a[N];
bool vis[128];
int cnt;
int ans[N];
int tmp[N];
int num[128];
bool check(int s)
{
int i = 1;
while(ans[i] == tmp[i] && i < N) i++;
if(tmp[i] > ans[i]) return true;
return false;
}
int main()
{
scanf("%d", &n);
scanf("%s", a+1);
for(int i = 1; i <= n; i++)
{
memset(vis, 0, sizeof(vis));
cnt = 0;
for(int j = i; j >= 1; j--)
{
if(!vis[a[j]]){
cnt++;
vis[a[j]] = true;
num[a[j]] = cnt;
}
tmp[j] = num[a[j]];
}
if(check(i)) {
for(int j = 1; j <= i; j++)
ans[j] = tmp[j];
}
// printf("DEBUG");
// for(int j = 1; j <= i; j++)
// {
// putchar('a'+tmp[j] - 1);
// }
// puts("");
}
int len = 1;
while(ans[len] != 0) len ++;
for(int i = 1; i < len; i++) putchar(ans[i]+'a'-1); puts("");
system("pause");
return 0;
}

H



输入样例1

5 6
1 2 1
1 3 2
1 4 3
4 3 4
4 5 5
2 5 6

输出样例1

21

输入样例2

6 5
1 2 4
2 3 1
3 4 3
4 5 2
5 6 5

输出样例2

12

输入样例3

5 5
1 2 1
2 3 2
3 4 3
4 5 4
5 1 5

输出样例3

14

更为详细的题解见此处https://blog.csdn.net/li_wen_zhuo/article/details/121633394

常规的思维是先输入图G,然后通过手段构建出L(G),然后求图里面的最大匹配。

现在我们反过来,把要求带到G图中。

L(G)中的一条边就相当于是G中的具有相同端点的两条边。同时,所选择的边不重复。

经过转化之后,经过奇思妙想

如果原图G中具有偶数条边,那么就可以选择所有的边。

证明:对于原图,是无环的,并且原图可以分为若干个连通块,每一个连通块连通并且无环,那么就是树。对于偶数个边的树:

(按照从叶子到根的方法进行考虑)

如果要是有一个节点具有偶数个儿子,那么这偶数个与儿子相连接的边两两组合。然后这一个节点变为叶子节点。

如果要是有一个节点具有奇数个儿子,那么这偶数个与儿子相连接的边两两组合。剩下的儿子,这一个节点,这一个节点的父亲所连接的边构成 具有相同端点的两条边

如果要是具有奇数条边,那么一定至少有一条边是无法进行匹配的。

删除一条边,按照常理所,剩下的就可以全部匹配了。但是可能这一条边恰恰是割边,并且删除这一条边以后形成的两个新的连通块中全部是奇数条边,那么就相当于有三条边无法匹配,所以损失过大,故是桥的这一条边还是不删为妙!

可以使用并查集来查看是否在同一个连通块里

由于对于每一个连通块都有可能出现有边无法匹配的情况,所以把边的权值从大到小进行排序(贪心),优先安排权值大的边。

注意:图论不一定是需要进行建图的,还可以仅仅存放点!

#include <bits/stdc++.h>
using namespace std;
#define N 300020
int fa[N], val[N];//与并查集结合使用
int n, m;
struct edge{
int x, y, w;
bool operator <(const edge &o){//从大到小进行排列
return w > o.w;
}
}a[N];
int get(int x)
{
if(x == fa[x]) return x;
return fa[x] = get(fa[x]);//BUG1:没有写 fa[x] =
}
int main()
{
scanf("%d%d", &n, &m);
for(int i = 1; i <= m; i++)
{
scanf("%d%d%d", &a[i].x, &a[i].y, &a[i].w);
}
sort(a+1, a+1+m);//BUG2:sort(a+1, a+1+n);
for(int i = 1; i <= n; i++){
fa[i] = i;
//val[i] = 0;如果是多组数据,就需要!
}
long long ans = 0;
for(int i = 1; i <= m; i++)
{
int x = get(a[i].x), y = get(a[i].y), w = a[i].w;
if(x == y){
if(val[x]){
ans += val[x] + w;
val[x] = 0;
}else{
val[x] = w;
}
}
else {//x != y
if(val[x] && val[y])//两边都是奇数,要选这一条边
{
ans += w + max(val[x], val[y]);
fa[x] = y;
val[y] = min(val[x], val[y]);
}
else if(!val[x] && !val[y])//两边是偶数,可以选这一条边,也可以不选。但是边是按照从大到小来进行排序的,所以暂时不选这一条边是最好的策略
{
fa[x] = y;
val[y] = w;
}
else {
ans += max(val[x], val[y])+w;
fa[x] = y;
val[y] = 0;
}
}
}
cout << ans;
return 0;
}

I



输入样例

2
-1 0 0 -1
0 1 -1 0
1 0 0 1
0 -1
-1 0 -1 0
0 1 0 -1
1 0 1 0
0 -1

输出样例

1.000000000000000 0.000000000000000
0.000000000000000 1.000000000000000

In the first sample case we have$ f(z)=iz$, and in the second sample case we have \(f(z)=1/z\).

题解&代码

没有什么好说的,敲就完了!

但是要注意一点:C++里面本来就有 复数这一个东西!

但是C++里面的复数的等于号有一点点阴间,所以等于根据精度判断一下就好了

#include<bits/stdc++.h>
#define ll long long
#define PII pair<int,int>
const double eps = 1e-6;
using namespace std; class Complex{
public:
double x, y;
Complex(){
x = 0;
y = 0;
}
Complex(double a, double b){
x = a;
y = b;
}
};
Complex operator + (const Complex &a, const Complex &b) {
return Complex( a.x + b.x, a.y + b.y );
}
Complex operator - (const Complex &a, const Complex &b) {
return Complex( a.x - b.x, a.y - b.y );
}
Complex operator * (const Complex &a, const Complex &b) {
return Complex( a.x*b.x-a.y*b.y, a.x*b.y+a.y*b.x);
}
Complex operator / (const Complex &a, const Complex &b) {
return Complex( (a.x*b.x+a.y*b.y)/(b.x*b.x + b.y*b.y), (a.y*b.x-a.x*b.y)/(b.x*b.x + b.y*b.y) );
}
bool operator == (const Complex &a, const Complex &b) {
if(fabs(a.x-b.x) < eps && fabs(a.y-b.y) < eps) return true;
else return false;
} Complex c[5][5], b[5];
int main()
{
int T;
cin >> T;
while(T--)
{
double tx, ty;
Complex z0, z1, z2, z3, w1, w2, w3, w0;
scanf("%lf%lf", &tx, &ty);
z1 = Complex(tx, ty);
scanf("%lf%lf", &tx, &ty);
w1 = Complex(tx, ty);
scanf("%lf%lf", &tx, &ty);
z2 = Complex(tx, ty);
scanf("%lf%lf", &tx, &ty);
w2 = Complex(tx, ty);
scanf("%lf%lf", &tx, &ty);
z3 = Complex(tx, ty);
scanf("%lf%lf", &tx, &ty);
w3 = Complex(tx, ty);
scanf("%lf%lf", &tx, &ty);
z0 = Complex(tx, ty);
Complex m, n;
m = (w1-w2)/(z1-z2);
n = (w1-m*z1);
if(m*z3+n == w3){//如果分母为0
w0 = m*z0 + n;
printf("%.15lf %.15lf\n", w0.x, w0.y);
continue;
}
Complex zero(0, 0);
c[1][1] = z1, c[1][2] = zero - w1, c[1][3] = Complex(1, 0);
c[2][1] = z2, c[2][2] = zero - w2, c[2][3] = Complex(1, 0);
c[3][1] = z3, c[3][2] = zero - w3, c[3][3] = Complex(1, 0);
b[1] = z1*w1;
b[2] = z2*w2;
b[3] = z3*w3;
//高斯的错
for(int i = 1; i <= 3; i++)
{
for(int j = i; j <= 3; j++)
{
if(!(c[j][i]==zero)){
for(int k = 1; k <= 3; k++) swap(c[i][k], c[j][k]);
swap(b[i], b[j]);
}
}
for(int j = 1; j <= 3; j++){
if(i == j) continue;
Complex rate = c[j][i] / c[i][i];
for(int k = i; k <= 3; k++)
{
c[j][k] = c[j][k] - c[i][k] * rate;
}
b[j] = b[j] - b[i] * rate;
}
}
Complex ans = (b[1]/c[1][1]*z0 + b[3]/c[3][3])/(z0+(b[2]/c[2][2]));
printf("%.15lf %.15lf\n", ans.x, ans.y);
} system("pause");
return 0;
}

J



输入样例

6
1234 2345
1234 0123
1234 2267
1234 3401
1234 1344
1234 2468

输出样例

1
1
4
5
1
4

这一道题目我们对先采用了大模拟,发现考虑的情况太多,然后又采用了暴力搜索。

参考题解:https://zhuanlan.zhihu.com/p/563484871

第 J 题

就如其中所说的,如果每一次都进行暴力,那么就有可能超时。

所以需要转变一下思路。

  1. 这其实就类似于高中物理的转化参考系,如果把最终的密码视为参考系,那么所有的测试样例就会全部转化为一种情况,搜索一次就可以满足所有的情况。
  2. 在搜索的时候采用BFS策略(可以求得最短的步数)
#include <bits/stdc++.h>
using namespace std;
map<string, int> mp;//其实使用数组也可以,但是把一个字符串映射为一个整数比较麻烦,so
queue<string> q; void bfs()
{
q.push("0000");
mp["0000"] = 0;
while(!q.empty())
{
string s = q.front();
q.pop();
//if(mp.count(s)) continue;
for(int i = 0; i < 4; i++)
{
for(int j = i; j < 4; j++)
{
string up = s;
string down = s;
for(int k = i; k <= j; k++)
{
up[k] = (up[k]-'0'+1)%10+'0';
down[k] = (down[k]-'0'-1+10)%10+'0';
}
if(!mp.count(up)) {
mp[up] = mp[s] + 1;
q.push(up);
}
if(!mp.count(down)) {
mp[down] = mp[s] + 1;
q.push(down);
}
}
} }
}
int main()
{
cin.tie(0);
ios::sync_with_stdio(0);//浅浅优化一下
//但是在这样搞了以后,就不要使用printf()了,可能导致输出顺序不一样然后寄掉
bfs();
int T;
cin >> T;
while(T--)
{
string a, b;
cin >> a >> b;
for(int i = 0; i < 4; i++){
b[i] = ((a[i]-'0')-(b[i]-'0')+10)%10+'0';
}
cout << mp[b] << "\n";
}
return 0;
}

第 46 届 ICPC 国际大学生程序设计竞赛亚洲区域赛(沈阳)的更多相关文章

  1. 2018 ACM 国际大学生程序设计竞赛上海大都会赛重现赛 F Color it

    链接:https://www.nowcoder.com/acm/contest/163/F 来源:牛客网 2018 ACM 国际大学生程序设计竞赛上海大都会赛重现赛 F Color it 时间限制:C ...

  2. 2018 ACM 国际大学生程序设计竞赛上海大都会赛重现赛 F Color it (扫描线)

    2018 ACM 国际大学生程序设计竞赛上海大都会赛重现赛 F Color it (扫描线) 链接:https://ac.nowcoder.com/acm/contest/163/F来源:牛客网 时间 ...

  3. 2018 ACM 国际大学生程序设计竞赛上海大都会赛重现赛 J Beautiful Numbers (数位DP)

    2018 ACM 国际大学生程序设计竞赛上海大都会赛重现赛 J Beautiful Numbers (数位DP) 链接:https://ac.nowcoder.com/acm/contest/163/ ...

  4. 2018 ACM 国际大学生程序设计竞赛上海大都会赛

    传送门:2018 ACM 国际大学生程序设计竞赛上海大都会赛 2018 ACM 国际大学生程序设计竞赛上海大都会赛重现赛2018-08-05 12:00:00 至 2018-08-05 17:00:0 ...

  5. 2018 ACM 国际大学生程序设计竞赛上海大都会赛重现赛 J Beautiful Numbers (数位dp)

    题目链接:https://ac.nowcoder.com/acm/contest/163/J 题目大意:给定一个数N,求区间[1,N]中满足可以整除它各个数位之和的数的个数.(1 ≤ N ≤ 1012 ...

  6. 2018 ACM 国际大学生程序设计竞赛上海大都会赛重现赛 A,D

    A链接:https://www.nowcoder.com/acm/contest/163/A Fruit Ninja is a juicy action game enjoyed by million ...

  7. 2018 ACM 国际大学生程序设计竞赛上海大都会赛重现赛-B-Perfect Numbers(完数)

    题目描述 We consider a positive integer perfect, if and only if it is equal to the sum of its positive d ...

  8. 2018 ACM 国际大学生程序设计竞赛上海大都会赛重现赛-K-Matrix Multiplication(矩阵乘法)

    题目描述 In mathematics, matrix multiplication or matrix product is a binary operation that produces a m ...

  9. “浪潮杯”第九届山东省ACM大学生程序设计竞赛(重现赛)E.sequence(树状数组求逆序对(划掉))

    传送门 E.sequence •题意 定义序列 p 中的 "good",只要 i 之前存在 pj < pi,那么,pi就是 "good": 求删除一个数, ...

随机推荐

  1. 使用marker的一些内容

    因为最近在搞uni-app的地图项目,所以大量使用了uni-app中的地图组件 虽然uni-app还是一个小学生水平,但是自己也想了很多 本期就来谈一谈uni-app中的marker,里面的好的内容和 ...

  2. 合并表格行---三层for循环遍历数据

    合并表格行---三层for循环遍历数据 示例1 json <!DOCTYPE html> <html lang="zh_cn"> <head> ...

  3. mysql grant命令

    增删改查的权限grant select on testdb.* to common_user@'%' grant insert on testdb.* to common_user@'%' grant ...

  4. 构建数据湖上低延迟数据 Pipeline 的实践

    T 摘要 · 云原生与数据湖是当今大数据领域最热的 2 个话题,本文着重从为什么传统数仓 无法满足业务需求? 为何需要建设数据湖?数据湖整体技术架构.Apache Hudi 存储模式与视图.如何解决冷 ...

  5. UE蓝图---实现场景物体Transform状态重置效果

    在工业领域应用中,通常会遇到操作场景模型变换的操作,经过了移动.旋转.缩放后,要求可一键重置还原最初的Transform状态. 思路:1.在模型阶段设置每个模型Tag值为Oper,表明是可被操作的对象 ...

  6. 一些有用的数学知识(Updating)

    文章目录 拉格朗日插值公式 微分中值定理 费马引理 拉格朗日中值定理 柯西中值定理 洛必达法则 连分数(NOI2021 D2T2 考点) 定义 结论 定理1 定理2 定理3 定理4 定理5 欧拉公式 ...

  7. 动态规划——leetcode55、跳跃游戏

    1.题目描述:  2.解题方法:动态规划 动态规划解题步骤: 1.确定状态: 最后一步:如果能跳到最后一个下标,我们考虑他的最后一步到n-1(最后一个下标),这一步是从 i 跳过来的,i<n-1 ...

  8. .Net Core&RabbitMQ死信队列

    过期时间 RabbitMQ可以为消息和队列设置过期时间Time To Live(TTL).其目的即过期. 消息过期时间 消息存储在队列中时,如果想为其设置一个有限的生命周期,而不是一直存储着,可以为其 ...

  9. centOS7.x修改root密码

    方法一: 在开机的时候选中这一行(注意光标要进入虚拟机),然后按下e键 然后找到这一行(linux 16开头的)其中的ro,将其改为 rw init=sysroot/bin/sh 按ctrl+x执行 ...

  10. .Net+Vue3实现数据简易导入功能

    在开发的过程中,上传文件或者导入数据是一件很常见的事情,导入数据可以有两种方式: 前端上传文件到后台,后台读取文件内容,进行验证再进行存储 前端读取数据,进行数据验证,然后发送数据到后台进行存储 这两 ...