这几道题都来自同一场比赛,这次把这几道题做一个整理。原题不说了,只说一下个别题的题目大意和思路。
A - Block Game
一个玄学的博弈问题,虽然没看懂,但是做出来了。
这里只说一下必胜态,1如果一个是另一个的倍数(特别的,两者相等)显然知道这是必胜态。2如果某个状态能拿的是两个以上,那么先手就能控制后手的走法,也就是可以给后手留下1次或者0次(也就是后手要拿另一堆),那么只要我们发现这种情况就算胜。否则就轮流拿,看能拿的次数的奇偶看胜负

#include <math.h>
#include <stdio.h>
#include <string.h>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <vector>
#include <iostream>
#include <algorithm>
//#include <bits/stdc++.h>
using namespace std;
typedef long long LL;int main()
{LL a, b;cin>>a>>b;if(a<b)swap(a, b);int x=a/b;int cnt=0;while(a!=0&&b!=0){if(a<b)swap(a, b);cnt++;if(a%b==0||a/2>=b) break;a=a%b;}if(cnt%2)puts("win");elseputs("lose");return 0;
}

B - Chess Tournament
有一些棋手,让他们自己汇报他们与其他的棋手的胜负情况,具有传递性(即a>b&&b>c 推出 a>c )问有没有说谎。三种情况胜、负、平。
看得出来是有向图判断成环,看得出是用拓扑排序
注意平局的情况,只能把他们几个棋手作为一个点,不能做条无向边,否则根据拓扑排序的原理知道不行。
可以利用并查集把相等的点变成一个点,把祖先作为点重新建图,(这样会有重边,但是根据拓扑排序的原理知道没事),点的数量就是根的数量(代码中的flag变量)

#include <math.h>
#include <stdio.h>
#include <string.h>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <vector>
#include <iostream>
#include <algorithm>
#define x first
#define y second
//#include <bits/stdc++.h>
using namespace std;
#define PII pair<int,int>
typedef long long LL;
const int N = 500010;
int n, m;
int pre[N];
int in[N];
int head[N], tot;
//map<int,int>mp;
//int dian;
queue<int>q;
struct node
{int v;int next;
} a[N];
vector<PII>big, small, deng;
void add(int u, int v)
{a[++tot].v = v, a[tot].next = head[u], head[u] = tot;
}
int fi(int x)
{if (pre[x] != x)pre[x] = fi(pre[x]);return pre[x];
}
void prework()
{for (int i = 0; i < N; i++)pre[i] = i;
}
void cinn()
{char c;int a, b;for (int i = 0; i < m; i++){scanf("%d %c %d", &a, &c, &b);if (c == '>')big.push_back({ a, b });else if (c == '<')small.push_back({ a, b });else{int x = fi(a);int y = fi(b);if (x != y)pre[x] = y;}}
}
bool topo()
{int cnt = 0;int flag = 0;for (int i = 0; i < n; i++)if (pre[i] == i){flag++;if (in[i] == 0) {q.push(i);cnt++;}}while (!q.empty()){int u = q.front();q.pop();in[u]--;for (int i = head[u]; i; i = a[i].next){int v = a[i].v;in[v]--;if (!in[v]){q.push(v);cnt++;}}}if (cnt == flag) return 1;else return 0;
}
int main()
{scanf("%d %d", &n, &m);prework();cinn();for (int i = 0; i < big.size(); i++){int xx = fi(big[i].x);int yy = fi(big[i].y);if (xx == yy){puts("inconsistent");return 0;}add(xx, yy);in[yy]++;}for (int j = 0; j < small.size(); j++){int xx = fi(big[j].x);int yy = fi(big[j].y);if (xx == yy){puts("inconsistent");return 0;}add(yy, xx);in[xx]++;}if (topo())puts("consistent");elseputs("inconsistent");return 0;
}

C - Completing the Square
知道正方形的三个点,找第四个,题目保证都是整数
最后一个点也是整数
求出三点的距离,相等的夹着的点就是对顶点。注意求距离别开方。

#include <math.h>
#include <stdio.h>
#include <string.h>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <vector>
#include <iostream>
#include <algorithm>
//#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
int x[5], y[5];
int len(int x1, int y1, int x2, int y2)
{int ret = (x1 - x2) * (x1 - x2) + (y1 - y2) * (y1 - y2);return ret;
}
void ans(int a, int b, int c)
{//    a--, b--, c--;int xx = x[b] + x[c] - x[a];int yy = y[b] + y[c] - y[a];printf("%d %d\n", xx, yy);
}
int main()
{int n = 3;for (int i = 0; i < n; i++)scanf("%d %d", &x[i], &y[i]);int a, b, c;a = len(x[0], y[0], x[1], y[1]);b = len(x[1], y[1], x[2], y[2]);c = len(x[0], y[0], x[2], y[2]);if (a == b)ans(1, 2, 0);else if (b == c)ans(2, 1, 0);elseans(0, 1, 2);return 0;
}

G - Millionaire Madness
给一个网格图,要求从左上走到右下,网格有高度,从低到高要用梯子,问梯子的最小高度。
用bfs,队列改为优先队列,按照梯子高度排序,先走梯子矮的,注意非负。
注意到达某个点所需要的梯子的高度可能会有变化,也就是某个点可能从别的方向上来会更好。如果发生这样的情况,那么队列里就会有多个相同点,但是这几个点的高度属性不同(易知其中必定有最低的那个路径),同时又必定是低的先进去,所以处理完一个点之后标记已经走过即可。

#include <math.h>
#include <stdio.h>
#include <string.h>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <vector>
#include <iostream>
#include <algorithm>
//#include <bits/stdc++.h>
#define x first
#define y second
#define PII pair<int,int>
using namespace std;
typedef long long LL;
int sx[] = { 1, 0, -1, 0 };
int sy[] = { 0, 1, 0, -1 };
int a[1002][1002];
bool vis[1002][1002];
int n, m;
int maxx;
priority_queue<pair<int, PII> >q;
void bfs(PII start)
{q.push({ 0,start });while (!q.empty()){PII u = q.top().y;int heigh = -q.top().x;q.pop();if (vis[u.x][u.y]) continue;vis[u.x][u.y] = 1;//cout << "**" << u.x << " " << u.y << " " << maxx << endl;if (maxx < heigh) maxx = heigh;if (u.x == n - 1 && u.y == m - 1) return;for (int i = 0; i < 4; i++){int xx = u.x + sx[i];int yy = u.y + sy[i];if (xx < 0 || yy < 0 || xx >= n || yy >= m ) continue;if (vis[xx][yy]) continue;PII v = make_pair(xx, yy);q.push({ -max(a[xx][yy] - a[u.x][u.y], 0), v });//注意负号}}
}
int main()
{cin >> n >> m;for (int i = 0; i < n; i++){for (int j = 0; j < m; j++)scanf("%d", &a[i][j]);}bfs({ 0, 0 });printf("%d\n", maxx);return 0;
}

kattis Block Game + Chess Tournament + Completing the Square + Millionaire Madness相关推荐

  1. Chess Tournament(思维题)

    题目 Chess Tournament 问题描述 有nnn个人参加比赛,两两之间进行对决,每两个人之间都会进行一次比赛: 对决有三种结果:要么胜,要么败,要么平. 选手有两种策略: 第一种:全场不败, ...

  2. CF1569B. Chess Tournament 简单思维

    B. Chess Tournament​​​​​​​ 题意:n个人 每两人间进行一次比赛,结果有胜平负三种.每个人要求1.不负 或2.至少胜一场, 给出n个人的要求(1or2),求能否满足所有人的要求 ...

  3. CodeForces - 1569B Chess Tournament

    CodeForces - 1569B AYIT609第一周周赛(2021) A chess tournament will be held soon, where n chess players wi ...

  4. 关于优先队列在图中的应用G - Millionaire Madness Kattis - millionairemadness

    G - Millionaire Madness Kattis - millionairemadness 文章大意:就是给你一个n*m的图(int)代表货物的高度),可以上下左右移动一次一格,但是去高度 ...

  5. 中石油训练赛 - Cafebazaar’s Chess Tournament(FFT)

    题目大意:给出 n 个队伍,每个队伍有两个属性分别记为 a 和 b ,如果队伍 i 和队伍 j 比赛: a[ i ] > a[ j ] && b[ i ] > b[ j ] ...

  6. upc Cafebazaar’s Chess Tournament 思维 + FFT

    说实话,题我没大读懂. 听zwz大佬说这个题挑战者的两个能力值不能与被挑战者能力值相等,不过可以取实数,所以这句话看没看到都不影响这个思路,因为每个相等的数都可以+0.1或-0.1来实现不相等且不影响 ...

  7. 1569 B.Chess Tournament

    题目 解题思路 如果玩家的希望为类型1,那么就令他与其他棋手的比赛全为平局 如果棋手的希望为类型2,这时候需要先考虑有几个希望为类型2的棋手,如果只有1个或者2个,那不可能满足条件(可以自己写写).当 ...

  8. Chess Tournament (巧用思维)

    文章目录 前言 个人理解 前言 开始一脸茫然-后来偷看了大佬的博客感觉超级nice,推一波 传送门 个人理解 感觉大佬的博客已经讲解的非常详细了,输出的结果只要满足: 1)整个方阵关于j=i这条线对称 ...

  9. CF1569B Chess Tournament

    原题链接 题意 思路 通过举例子发现,至少赢一次的人数小于等于2同时不等于0时,是NO, 还有的至少赢一次的就赢一次,赢另一个至少赢一次的人,剩余的全部都平局即可. 代码 #include<bi ...

最新文章

  1. NVIDIA 认证系统
  2. 生化医学文章模式图素材
  3. 小程序中textarea层级最高的结局办法
  4. 蓝牙的发展史及版本演进
  5. Android开发--环境的配置
  6. IDEA启动Tomcat AJP连接器配置secretRequired=“true“,但是属性secret确实空或者空字符串,这样的组合是无效的解决办法
  7. Android系统Recovery工作原理之使用update.zip升级过程分析(二)---u...
  8. A.PHP读取txt文本文件并分页显示的方法
  9. 基于Qt的P2P局域网聊天及文件传送软件设计
  10. 李国庆深夜发“15条真相”回应:关于原生家庭、同性恋、1.3亿...
  11. uniapp 开发h5 优化加载速度
  12. 《面向对象程序设计》课程作业 (三)
  13. 区块链爆史诗级漏洞,可完全控制虚拟货币交易!
  14. cocoapods 更新指定的第三方库
  15. 黑客帝国里的代码雨-java代码实现
  16. 微信公众号怎么清缓存
  17. 回忆旧时读叶芝的WHEN YOU ARE OLD
  18. android内存最小版本下载,猫和老鼠精简版下载-猫和老鼠内存最小版下载v6.6.1 安卓版-芒果手游网...
  19. 道达尔远景光伏助力中天钢铁打造低碳绿色钢城
  20. H.266/VVC帧间预测技术学习:几何划分模式(Geometric partitioning mode, GPM)

热门文章

  1. js Decimal
  2. 中科院Java高端培训视频教程
  3. 有了dedecms仿站专用工具,仿站如此简单
  4. 逻辑器件功耗计算——CMOS的静态功耗与动态功耗
  5. 错误代码:0x800704cf 不能访问网络位置
  6. HTTP客户端错误状态码--4XX
  7. 【BZOJ 1862】 [Zjoi2006]GameZ游戏排名系统
  8. 蓝桥杯2018年省赛真题--全球变暖
  9. linux网卡汇聚带宽,iperf压测linux网卡带宽
  10. 乌班图系统重启服务器,如何快速重启ubuntu系统