首页 > 其他分享 >test20230225考试总结

test20230225考试总结

时间:2023-02-25 17:13:34浏览次数:60  
标签:总结 ch return val int test20230225 read 考试 define

前言

I hate questions that already exist!!
我讨厌原题!!

赛时得分明细:

A B C D E F Total Rank
100 100 10 56 0 44 310 6

A. P1993 小 K 的农场

题面

给定长度为 \(n\) 的数组 \(A_1,A_2,A_3,\dots,A_n\) 和 \(m\) 个约束条件,约束条件有三种:

  • \(1\) \(x\) \(y\) \(c\) :\(A_x - A_y \ge c\);
  • \(2\) \(x\) \(y\) \(c\) :\(A_x - A_y \le c\);
  • \(3\) \(x\) \(y\) :\(A_x = A_y\);

输出是否存在合法的自然数解。存在输出 "\(Yes\)", 不存在输出 "\(No\)"。

\(1 \le n,m \le 5 \times 10^3\)

题解

差分约束模板

可以尝试把 \(A_x - A_y \ge c\) 转化为 \(A_y \le A_x - c\),把 \(A_x - A_y \le c\) 转化为 \(A_x \le A_y + c\)。

\(A_x = A_y\) 可以转化为 \(A_x - A_y = 0\),进而变成 \(A_x - A_y \le 0\) 且 \(A_x - A_y \ge 0\)。

每次遇到一个约束条件就将建 \(5\) 条边:

  1. \(x \to y\),权值为 \(-w\);
  2. \(y \to x\),权值为 \(w\);
  3. \(x \to y\),权值为 \(0\);
  4. \(y \to x\),权值为 \(0\);

建一个超级点,跑最短路即可。但不能用 \(dijkstra\),因为存在负环(或是要判负环)。

代码

#include <bits/stdc++.h>
#define int long long
#define H 19260817
#define rint register int
#define For(i,l,r) for(rint i=l;i<=r;++i)
#define FOR(i,r,l) for(rint i=r;i>=l;--i)
#define MOD 1000003
#define mod 1000000007

using namespace std;

inline int read() {
  rint x=0,f=1;char ch=getchar();
  while(ch<'0'||ch>'9'){if (ch=='-') f=-1;ch=getchar();}
  while(ch>='0'&&ch<='9'){x=(x<<1)+(x<<3)+(ch^48);ch=getchar();}
  return x*f;
}

void print(int x){
  if(x<0){putchar('-');x=-x;}
  if(x>9){print(x/10);putchar(x%10+'0');}
  else putchar(x+'0');
  return;
}

const int N = 1e6 + 10;

struct Node {
  int v, w;
}; 

int n, m, q[N], dist[N], cnt[N];

bool st[N];

vector <Node> e[N];

bool spfa() {
  int h = 1, t = 0;
  memset(dist, 0x3f, sizeof dist);
  memset(st, 0, sizeof st);
  memset(cnt, 0, sizeof cnt);
  q[++t] = 0, st[0] = 1, dist[0] = 0;
  while(h <= t) {
    int x = q[h++];
    st[x] = 0;
    for (int i = 0; i < e[x].size(); i++) {
      int y = e[x][i].v, w = e[x][i].w;
      if(dist[y] > dist[x] + w) {
        dist[y] = dist[x] + w;
        cnt[y] = cnt[x] + 1;
        if(cnt[y] >= n + 1) return 0;
        if(!st[y]) {
          q[++t] = y;
          st[y] = 1;
        }
      }
    }
  }
  return 1;
}

void add(int u, int v, int w) {
  e[u].push_back((Node){v, w});
}

signed main() {
    n = read(), m = read();
    For(i,1,m) {
    int op = read(), x = read(), y = read();
    if(op == 1) {
      int w = read();
      add(x, y, -w);
    } else if(op == 2) {
      int w = read();
      add(y, x, w);
    } else {
      add(x, y, 0);
      add(y, x, 0);
    } 
  }
  For(i,1,n) add(0, i, 0);
  puts(spfa()?"Yes":"No"); 
  return 0;
}

B. P2294 [HNOI2005]狡猾的商人

题面

对于一个长度为 \(n\) 的数组,给定 \(m\) 个部分和 \(\sum_{l=1}^{r} A_i\),判断该数组是否合法(合法输出 "\(Yes\)",不合法输出 "\(No\)")。

题解

代码

#include <bits/stdc++.h>
#define int long long
#define H 19260817
#define rint register int
#define For(i,l,r) for(rint i=l;i<=r;++i)
#define FOR(i,r,l) for(rint i=r;i>=l;--i)
#define MOD 1000003
#define mod 1000000007

using namespace std;

inline int read() {
  rint x=0,f=1;char ch=getchar();
  while(ch<'0'||ch>'9'){if (ch=='-') f=-1;ch=getchar();}
  while(ch>='0'&&ch<='9'){x=(x<<1)+(x<<3)+(ch^48);ch=getchar();}
  return x*f;
}

void print(int x){
  if(x<0){putchar('-');x=-x;}
  if(x>9){print(x/10);putchar(x%10+'0');}
  else putchar(x+'0');
  return;
}

const int N = 2e5 + 10;

int n, m, Q, f[N], val[N];

int find(int x) {
  if(x == f[x]) return x;
  else {
    int root = find(f[x]);
    val[x] += val[f[x]];
    return f[x] = root;
  }
}

signed main() {
  Q = read();
  while(Q--) {
    bool vis = 0;
    n = read(), m = read();
    For(i,0,n) f[i] = i, val[i] = 0;
    For(i,1,m) {
      int l = read(), r = read(), s = read();
      l--; 
      int t1 = find(l), t2 = find(r);
      if(t1 != t2) {
        f[t2] = t1;
        val[t2] = val[l] + s - val[r];
      } else {
        if(val[r] - val[l] != s) {
          vis = 1;
          puts("false");
          break;
        }
      }
    } 
    if(!vis) puts("true");
  }
  return 0;
}

C. P7624 [AHOI2021初中组] 地铁

题面

题解

代码

D. P6378 [PA2010] Riddle

题面

题解

代码

E. P3513 [POI2011] KON-Conspiracy

题面

题解

代码

F. P5905 【模板】Johnson 全源最短路

题面

题解

代码

标签:总结,ch,return,val,int,test20230225,read,考试,define
From: https://www.cnblogs.com/Daniel-yao/p/17154440.html

相关文章

  • [专题总结]Gridea快速免费搭建个人博客
    介绍或许你很想把你所知道的问题写出来,或许你文思泉涌,想给大家分享。我相信,你一定能写好博客,只要坚持,就可以了。或许大家会不理解,为什么不用大平台的博客呢?或许你稍微了......
  • SQuirrel client UI 操作hbase 及 spark with phoenix 写hbase 遇到的一些问题总结
    1:在SQuirrel里如果创建table的时候,不指定namespace,则表是创建在default空间的,在UI上无法看到,但是在phoenixsqlline命令行可以看到,如下表LOT7  2:phoenixsql里,如果......
  • 助教工作总结
    一、助教工作的具体职责和任务 (包括:你和老师是如何配合的、你和课程其他助教是如何配合的(如果有的话))本学期作为前端开发技术助教,主要是负责:配合老师:1.帮助老师批改作业......
  • Redis笔记总结之redis介绍
    摘自:https://www.cnblogs.com/demoKing/p/8573873.html一、Redis介绍:redis的发展历史简单的理解为因为使用类似MySql这类关系型数据库不方便进而开发的开......
  • 推荐系统[八]算法实践总结V1:淘宝逛逛and阿里飞猪个性化推荐:召回算法实践总结【冷启动
    0.前言:召回排序流程策略算法简介推荐可分为以下四个流程,分别是召回、粗排、精排以及重排:召回是源头,在某种意义上决定着整个推荐的天花板;粗排是初筛,一般不会上复杂模型;......
  • 2023/2/25 考试总结
    题单:clickhereT1.P2542[AHOI2005]航线规划虽然一眼\(\mathtt{LCT}\),但没有思考(?)使用一种简陋的方式获得了\(\mathtt{50pts}\)。用树链剖分也可做。首先是逆序......
  • 计算机理论自我总结
    目录​​权衡​​​​全局/系统思维​​​​理论实践的指导、验证​​​​参考​​权衡一个方面的数据提升,可能意味着其他方面的损耗。一个好的方案/架构,应该是在全局思维考......
  • 助教工作总结202302
    一、助教工作的具体职责和任务:(1)协助并分担老师的工作,在线下对学生课上不理解的部分进行一定的指导,比如大作业的评分以及提供一些学习建议。(2)询问其他助教,分析目前学生的......
  • 每日总结(6)
    所用时间:代码:博客:知识点:安装AndroidStudio参考博客: Androidstudio安装教程_一纸梦的博客-CSDN博客_androidstudio遇到错误:No cached version of com.a......
  • 学习中设计模式的总结
    首先要了解什么是设计模式呢?设计模式:可以简单的理解为两个字“经验”,就是码农们在各种需求中间,总结出来的一种最优的解法称之为设计模式;1,单例模式......