第 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": 求删除一个数, ...
随机推荐
- Frame双向通信插件FrameDataTrans
FrameDataTrans教程 博客园 乳鸽菌 20220729 核心原理是使用postMessage发送数据,window.addEventListener("message" ...
- MySQL客户端工具的使用与MySQL SQL语句
MySQL客户端工具的使用 1.MySQL程序的组成 客户端 mysql:CLI交互式客户端程序 mycli:CLI交互式客户端程序;使用sql语句时会有提示信息 mysql_secure_insta ...
- Swift高仿iOS网易云音乐Moya+RxSwift+Kingfisher+MVC+MVVM
效果 列文章目录 因为目录比较多,每次更新这里比较麻烦,所以推荐点击到主页,然后查看iOS Swift云音乐专栏. 目简介 这是一个使用Swift(还有OC版本)语言,从0开发一个iOS平台,接近企业 ...
- Golang 汇编asm语言基础学习
Golang 汇编asm语言基础学习 一.CPU 基础知识 cpu 内部结构 cpu 内部主要是由寄存器.控制器.运算器和时钟四个部分组成. 寄存器:用来暂时存放指令.数据等对象.它是一个更快的内存. ...
- Redis 14 发布订阅
参考源 https://www.bilibili.com/video/BV1S54y1R7SB?spm_id_from=333.999.0.0 版本 本文章基于 Redis 6.2.6 概述 Redi ...
- 使用idea remote 开发体验
本地使用idea开发最不好的一个体验就是打开稍大的工程就非常的卡,怎么调参数都没用,现在idea推出了idea remote就赶紧来体验下. 使用方式 除了idea不需要额外下载什么包,但是因为rem ...
- anltr 解析MYSQL
String sql = "select a as c,b as s,'zhange' F, 1/5 as e from t_order"; final MysqlQueryLex ...
- linux centos7开启防火墙端口
firewall-cmd --zone=public --add-port=3306/tcp --permanent firewall-cmd --reload
- 文心大模型api使用
文心大模型api使用 首先,我们要获取硅谷社区的连个key 复制两个api备用 获取Access Token 获取access_token示例代码 之后就会输出 作文创作 作文创作:作文创作接口基于文 ...
- Think PHP框架基础安装6.0
第一步:点击基础安装tp框架composer create-project topthink/think tp 第二步:点击架构多应用模式 拓展composer require topthink/th ...