第 46 届 ICPC 国际大学生程序设计竞赛亚洲区域赛(沈阳)
有时候,很简单的模板题,可能有人没有做出来,(特指 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 题
就如其中所说的,如果每一次都进行暴力,那么就有可能超时。
所以需要转变一下思路。
- 这其实就类似于高中物理的转化参考系,如果把最终的密码视为参考系,那么所有的测试样例就会全部转化为一种情况,搜索一次就可以满足所有的情况。
- 在搜索的时候采用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 国际大学生程序设计竞赛亚洲区域赛(沈阳)的更多相关文章
- 2018 ACM 国际大学生程序设计竞赛上海大都会赛重现赛 F Color it
链接:https://www.nowcoder.com/acm/contest/163/F 来源:牛客网 2018 ACM 国际大学生程序设计竞赛上海大都会赛重现赛 F Color it 时间限制:C ...
- 2018 ACM 国际大学生程序设计竞赛上海大都会赛重现赛 F Color it (扫描线)
2018 ACM 国际大学生程序设计竞赛上海大都会赛重现赛 F Color it (扫描线) 链接:https://ac.nowcoder.com/acm/contest/163/F来源:牛客网 时间 ...
- 2018 ACM 国际大学生程序设计竞赛上海大都会赛重现赛 J Beautiful Numbers (数位DP)
2018 ACM 国际大学生程序设计竞赛上海大都会赛重现赛 J Beautiful Numbers (数位DP) 链接:https://ac.nowcoder.com/acm/contest/163/ ...
- 2018 ACM 国际大学生程序设计竞赛上海大都会赛
传送门:2018 ACM 国际大学生程序设计竞赛上海大都会赛 2018 ACM 国际大学生程序设计竞赛上海大都会赛重现赛2018-08-05 12:00:00 至 2018-08-05 17:00:0 ...
- 2018 ACM 国际大学生程序设计竞赛上海大都会赛重现赛 J Beautiful Numbers (数位dp)
题目链接:https://ac.nowcoder.com/acm/contest/163/J 题目大意:给定一个数N,求区间[1,N]中满足可以整除它各个数位之和的数的个数.(1 ≤ N ≤ 1012 ...
- 2018 ACM 国际大学生程序设计竞赛上海大都会赛重现赛 A,D
A链接:https://www.nowcoder.com/acm/contest/163/A Fruit Ninja is a juicy action game enjoyed by million ...
- 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 ...
- 2018 ACM 国际大学生程序设计竞赛上海大都会赛重现赛-K-Matrix Multiplication(矩阵乘法)
题目描述 In mathematics, matrix multiplication or matrix product is a binary operation that produces a m ...
- “浪潮杯”第九届山东省ACM大学生程序设计竞赛(重现赛)E.sequence(树状数组求逆序对(划掉))
传送门 E.sequence •题意 定义序列 p 中的 "good",只要 i 之前存在 pj < pi,那么,pi就是 "good": 求删除一个数, ...
随机推荐
- MyBatis-通用Mapper-tk.mybatis的使用
MyBatis-通用Mapper[更新中] tk.mybatis的使用 前言 使用MyBatis开发,如果是普通是同MyBatis进行开发,那么就需要在xml文件中编写大量的SQL.当数据库表结构发生 ...
- 汽车锂电池行业为啥会选择钡铼BL200系列Profinet分布式IO
近年来,全球新能源汽车的蓬勃发展促进了锂电池行业的发展.随着锂电池标准化程度的提高,电池和模块规格的标准化是未来的发展趋势,也促进了自动化模块生产线的发展. 锂电池模块生产线通过涂胶-电池堆叠-组装- ...
- && 和 ||粗解
可以这么理解 &&是来找假的,如果找到假就返回假,如果找不到,就返回最后一个真 ||是来找真的,如果找到真就返回真,如果找不到,就返回最后一个假 var speed = 12; var ...
- 故障案例 | 一次慢SQL优化分析全过程
欢迎来到 GreatSQL社区分享的MySQL技术文章,如有疑问或想学习的内容,可以在下方评论区留言,看到后会进行解答 GreatSQL社区原创内容未经授权不得随意使用,转载请联系小编并注明来源. 客 ...
- 美女 Committer 手把手教你使用海豚调度
还在为选哪个调度发愁么?还在为查使用手册愁眉不展么?来来来,先瞧一眼海豚调度的 Slogan:调度选的好,下班回家早.调度用的对,半夜安心睡.为充分贯彻这一宗旨,海豚调度一条龙服务来了,特地邀请海豚社 ...
- Taurus.MVC WebAPI 入门开发教程6:全局控制器DefaultController与全局事件。
系列目录 1.Taurus.MVC WebAPI 入门开发教程1:框架下载环境配置与运行. 2.Taurus.MVC WebAPI 入门开发教程2:添加控制器输出Hello World. 3.Tau ...
- 延时任务-基于netty时间轮算法实现
一.时间轮算法简介 为了大家能够理解下文中的代码,我们先来简单了解一下netty时间轮算法的核心原理 时间轮算法名副其实,时间轮就是一个环形的数据结构,类似于表盘,将时间轮分成多个bucket(比如: ...
- 零基础学Java(14)对象构造
对象构造 之前学习了编写简单的构造器,可以定义对象的初始状态.但是,由于对象构造非常重要,所以Java提供了多种编写构造器的机制. 重载 有些类有多个构造器.例如,可以如下构造一个空的StringBu ...
- JWT漏洞学习
JWT漏洞学习 什么是JWT? JWT是JSON Web Token的缩写,它是一串带有声明信息的字符串,由服务端使用加密算法对信息签名,以保证其完整性和不可伪造性.Token里可以包含所有必要的信息 ...
- 【MIDO】乐理基础 与 python - 从零开始到编写柱式和弦与分解和弦
本篇文章从律学开始,从十二平均律出发,介绍一些基础必要的乐理知识,然后编写python文件,输出和弦音频文件. 乐理知识部分: 一.律学简述(temperament) 1.概论 律学,又称&q ...