CodeTON Round 4 (Div. 1 + Div. 2, Rated, Prizes!) (D,E)
Problem - D - Codeforces
思路:大模拟
- 我们只需要对所有操作1确认它至少x米可以上top,至多y米必定上top来确认是否使用,只要每次操作1对于当前区间[l,r](上top区间)有x<=r&&y>=l,那么可以采纳,并且更新l,r。否则不用
- 对于操作2,我们只需判断在最少米与最高米上top天数是否相同,是则采纳,否则-1
- 判断天数ans是否相同(以l为例),有
。向上取整,所以我们给分子加上分母-1(即a-b-1),所以得到
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define endl "\n"
#define int ll
int32_t main()
{std::ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);int t,q,op,a,b,n,x,y;cin>>t;while (t--){cin>>q;int l=1,r=1e18;while (q--){cin>>op>>a>>b;if (op==1){cin>>n;if (n==1){x=1,y=a;}else{x=1+a*(n-1)-b*(n-2);y=(a-b)*(n-1)+a;}if (y>=l&&x<=r)//判断是否采用,是则更新区间,尽量缩小它{cout<<1<<" ";l=max(l,x),r=min(r,y);}else cout<<0<<" ";}else{x=a>=l?1LL:(l-b+a-b-1)/(a-b);y=a>=r?1LL:(r-b+a-b-1)/(a-b);if (x==y)cout<<x<<" ";else cout<<-1<<" ";}}cout<<endl;}system("pause");return 0;
}
Problem - E - Codeforces
思路:并查集
- 如果有解,必然存在从一个u(a[u]=0),可以走过所有点。
- 我们可以走所有a[i]=0的点(前提是它没有被别人来过),然后记录这个点可以走过的所有点(把这些点都归为当前i这个集合,并且存储这个集合的点数)
- 我们每次走时,如果遇到集合u(或者点),并且我x(从x出发)当前消灭怪物数,那么我把这个集合吸收。
- 遍历完后,如果有一个点可以吸收所有点,有解
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define endl "\n"
typedef pair<long long, long long> pll;
const int N = 2e5 + 10;int a[N],fa[N],cnt[N];
int vis[N];
struct node
{int next,to;
} edge[N<<1];
int head[N],num;
int t,n,m;inline void init()
{for (int i=0; i<=n; ++i)head[i]=0,fa[i]=i,cnt[i]=1,vis[i]=0;num=0;
}inline void add(int u,int v)
{edge[++num].next=head[u];edge[num].to=v;head[u]=num;
}inline int find(int u)//并查集找祖先
{if (u!=fa[u])fa[u]=find(fa[u]);return fa[u];
}bool check(int x)//检查从x出发是否可以经过所有点
{set<pll>s;//用set存储,每次取a[i]最小的点出来s.insert({a[x],x});while (!s.empty()){int u=(*s.begin()).second;s.erase(s.begin());if (a[u]>cnt[x])return (cnt[x]==n);//如果这个点到不了,后面都到不了,直接返回int tmp=find(u);if (tmp!=x)fa[tmp]=x,cnt[x]+=cnt[tmp],cnt[tmp]=0;//如果这个点的祖先不是x,吸收这个祖先的集合for (int i=head[u]; i; i=edge[i].next){int v=edge[i].to;if (vis[v]<x)//vis两个功能,1个是判断a[i]=0的点有没有被访问过,有则main函数不用来了,而是一个check(x)回合避免多次访问一个点vvis[v]=x,s.insert({a[v],v});}}return (cnt[x]==n);
}int32_t main()
{std::ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);cin>>t;while (t--){cin>>n>>m;init();for (int i=1; i<=n; ++i)cin>>a[i];int x,y;for (int i=1; i<=m; ++i){cin>>x>>y;add(x,y),add(y,x);}bool flag=0;for (int i=1; i<=n; ++i)if (a[i]==0&&!vis[i])if (check(i)){cout<<"YES"<<endl;flag=1;break;}if (!flag)cout<<"NO"<<endl;}system("pause");return 0;
}
CodeTON Round 4 (Div. 1 + Div. 2, Rated, Prizes!) (D,E)相关推荐
- CodeTON Round 4 (Div. 1 + Div. 2, Rated, Prizes!)A~E
比赛连接:Dashboard - CodeTON Round 4 (Div. 1 + Div. 2, Rated, Prizes!) - Codeforces A. Beautiful Sequenc ...
- Deltix Round, Summer 2021 (open for everyone, rated, Div. 1 + Div. 2)
Deltix Round, Summer 2021 (open for everyone, rated, Div. 1 + Div. 2) 题号 题目 知识点 A A Variety of Opera ...
- Deltix Round, Spring 2021 (open for everyone, rated, Div. 1 + Div. 2)
Deltix Round, Spring 2021 (open for everyone, rated, Div. 1 + Div. 2) 题号 题目 知识点 A Game of Life B Lor ...
- Codeforces Round #504 (rated, Div. 1 + Div. 2, based on VK Cup 2018 Final)切题报告(A-B题)
这是我第二次参加CF比赛,也是第一次写博客,写得不好,望各位大佬海涵. A. Single Wildcard Pattern Matching 原题链接 这道题,这是难到让人无法直视,太水了. 题目大 ...
- [区间记忆化dp入门][Bribe the Prisoners SPOJ - GCJ1C09C][Codeforces Round #505D (rated, Div. 1 + Div. 2, ba]
Bribe the Prisoners SPOJ - GCJ1C09C 作为这类题代表,f[i][j]代表第i点到第j点单独处理的最值 这题关键:释放某个囚犯后,就把囚犯分成两段,两段互相独立 这类d ...
- Codeforces Round #586 (Div. 1 + Div. 2) B. Multiplication Table 思维 + 公式
传送门 文章目录 题意: 思路: 题意: 给你一个n∗nn*nn∗n的矩阵,每个位置由ai∗aja_i*a_jai∗aj得来,主对角线为000,让你求出来aia_iai. n≤1e3n\le1e ...
- Codeforces Round #586 (Div. 1 + Div. 2) D. Alex and Julian 数学 + 思维
传送门 文章目录 题意: 思路: 题意: 给你一个无限个点的坐标轴,一个集合BBB,如果存在∣i−j∣=bk|i-j|=b_k∣i−j∣=bk的话,那么i,ji,ji,j之间就连边.现在问你至少要从 ...
- Codeforces Round #733 (Div. 1 + Div. 2) E. Minimax 分情况讨论 + 思维
传送门 文章目录 题意: 思路: 题意: 给你一个串,你可以随意安排这个串,使得这个串的每个前缀的kmpkmpkmp数组最大值最小,定义为f(a)f(a)f(a),并且字典序最小,输出安排之后的串. ...
- Manthan, Codefest 19 (open for everyone, rated, Div. 1 + Div. 2) F. Bits And Pieces sosdp预处理超集
传送门 文章目录 题意: 思路: 题意: n≤1e6,ai≤2e6n\le1e6,a_i\le2e6n≤1e6,ai≤2e6 思路: 由于(aj&ak)(a_j \And a_k)(aj& ...
- Ozon Tech Challenge 2020 (Div.1 + Div.2, Rated) D. Kuroni and the Celebration 交互 + 思维
传送门 文章目录 题意: 思路: 题意: 给你一颗树,每次可以询问两个点的lcalcalca,询问次数不能超过⌊n2⌋\left \lfloor \frac{n}{2} \right \rfloor⌊ ...
最新文章
- boost::random模块使用多精度类型测试所有与整数相关的生成器和分布的测试程序
- java iterator map_Java循环遍历输出map方法
- js中的escape的用法汇总
- PPT下载下来是php,用php下载jpg,doc,ppt文件已损坏
- php如何统计数组的个数,如何用php统计数组元素的个数(附代码)
- Log4j未平,Logback 又起,再爆漏洞。
- 外接显示器设置_如何为一台电脑设置两个显示器
- 关于分布式集群的几个问题
- Bailian4111 判断游戏胜者-Who Is the Winner【文本处理】
- 24种不同的ITF条形码字体Interleaved 2 of 5 Barcode Font Advantage Package
- ATK-DTU-M750 物联网模块+MQTT(阿里云)配置(一)
- 罗塞塔石碑1141问题
- WIN10-VS2019-SeetaFace6编译
- 人工智能算法对发明创造的知识产权保护
- 【Redis之ZSet类型的详解ZSet类型中常用命令的实践】
- 高校bbs或者科研论坛
- 那些年UNIX教我们的事
- 凯撒密码c++语言程序,凯撒密码(加密与解密)
- Chrome 的7大缺陷以及相关解决方案
- [机器学习] 线性回归