Educational Codeforces Round 58 A,B,C,D,E,G
A. Minimum Integer
链接:http://codeforces.com/contest/1101/problem/A
代码:
#include<bits/stdc++.h>
using namespace std;
#define ll long long int main()
{
int n,x,y,d;
cin >> n;
for(int i = ;i <= n;i ++){
cin>>x>>y>>d;
if(x > d) cout<<d<<endl;
else {
int k = y/d+;
cout<<k*d<<endl;
}
}
return ;
}
B. Accordion
链接:http://codeforces.com/contest/1101/problem/B
思路:给你一个字符串你可以删除任何一个字符,问能组成最长的符合要求的字符长度。要求为:开头必须为[:结尾必须为:],中间可以有任意数量的|,我们只要找到最先出现的[:和最后出现的:],然后统计下两个:之间有多少个|就好了
实现代码;
#include<bits/stdc++.h>
using namespace std;
#define ll long long int main()
{
string s;
cin>>s;
int flag = ;
int len = s.size();
int st = -,ed = -,t = -,d = -;
for(int i = ;i < len;i ++){
if(s[i]=='['&&flag == ){
flag = ;st = i;
}
if(flag==&&s[i]==':'){
t = i;break;
}
}
flag = ;
for(int i = len-;i >= ;i --){
if(s[i]==']'&&flag == )flag = ,ed=i;
if(flag==&&s[i]==':'){
d = i;break;
}
}
// cout<<st<<" "<<ed<<" "<<t<<" "<<d<<endl;
if(st==-||ed==-||t==-||d==-||t>=d||st>ed)
cout<<-<<endl;
else{
int ans = ;
for(int i = t;i <= d;i ++){
if(s[i]=='|') ans++;
}
cout<<+ans<<endl;
}
}
C. Division and Union
链接:http://codeforces.com/contest/1101/problem/C
思路:要求两个集合内的区间不能有重合的,那么我们只要找到有一段有间隔的将前一部分设为集合1,后部分设为集合二,那么两个集合绝对不会存在交集
实现代码:
#include<bits/stdc++.h>
using namespace std;
#define ll long long const int M = 2e5 + ; struct node{
int x,y,id;
}a[M]; int ans[M];
bool cmp(node a,node b){
if(a.x == b.x) return a.y < b.y;
return a.x < b.x;
} int main()
{
int t,n;
cin>>t;
while(t--){
cin>>n;
int mx = ;
for(int i = ;i <= n;i ++){
cin>>a[i].x>>a[i].y;
a[i].id = i;
mx = max(a[i].y,mx);
}
sort(a+,a++n,cmp);
int ed = a[].x,flag = ;
for(int i = ;i <= n;i ++){
if(a[i].x > ed&&flag == ) flag = ;
if(flag==) ans[a[i].id] = ;
else ans[a[i].id] = ;
ed = max(ed,a[i].y);
}
if(!flag) cout<<-<<endl;
else {
for(int i = ;i <= n;i ++){
cout<<ans[i]<<" ";
}
cout<<endl;
}
} rn ;
}
D. GCD Counting
题意:
给你一颗树,树上各个点有权值,要求gcd(x,y) > 1的情况下 树上最长的长度,gcd(x,y)就是求树上x到y路径上所有点权值的gcd
思路:
要想x-y路径上gcd大于1,那么路径上的数都要是某个大于1的数的倍数,对一个数我们可以求出他可以为哪些数的倍数,所有数求完之后对于一个数我们也可以知道他在这棵树里有哪些数是他的倍数,我们每次标记下这些点为可用点,然后dfs求下当前点最远能到哪里(只能走可用点),然后比较与之前的最大长度比较。这样每个都跑完最大的就是答案。
实现代码:
#include<bits/stdc++.h>
using namespace std;
#define ll long long const int M = 2e5 + ; int vis[M],ans,a[M];
vector<int>g[M],v[M];
int dfs(int u){
int mx = ;
vis[u] = ;
for(int i = ;i < g[u].size();i ++){
int v = g[u][i];
if(!vis[v]) continue;
int k = dfs(v);
ans = max(ans,k++mx);
mx = max(mx,k);
}
ans = max(ans,);
return mx + ;
} int main()
{
int n,x,y;
scanf("%d",&n);
for(int i = ;i <= n;i ++){
scanf("%d",&a[i]);
for(int j = ;j*j <= a[i];j ++){
if(a[i]%j) continue;
v[j].push_back(i);
if(j*j != a[i]) v[a[i]/j].push_back(i);
}
}
for(int i = ;i < n;i ++){
scanf("%d%d",&x,&y);
g[x].push_back(y);
g[y].push_back(x);
}
for(int i = ;i <= M;i ++){
for(int j = ;j < v[i].size();j ++) vis[v[i][j]] = ;
for(int j = ;j < v[i].size();j ++)
if(vis[v[i][j]]) dfs(v[i][j]);
}
cout<<ans<<endl;
return ;
}
E. Polycarp's New Job
链接:
思路:题目上写了要求,if either x≤h and y≤w or y≤h and x≤w.按这个要求写个判断,记录下输入的最大长和宽,如果宽大于长,那么调换下位子,最后用题目要求判断下就好了。
代码:
#include<bits/stdc++.h>
using namespace std;
#define ll long long const int M = 2e5 + ;
int n,x,y,mx,my;
int main()
{
char op[];
scanf("%d",&n);
for(int i = ;i <= n;i ++){
scanf("%s",op);
scanf("%d%d",&x,&y);
if(op[]=='+'){
if(x > y) swap(x,y);
mx = max(mx,x);
my = max(my,y);
}
else{
int flag = ;
if(mx<=x&&my<=y) flag = ;
if(mx<=y&&my<=x) flag = ;
if(flag) printf("YES\n");
else printf("NO\n");
}
}
return ;
}
G. (Zero XOR Subset)-less
链接:http://codeforces.com/contest/1101/problem/G
题目:给你一段序列,你可以把它分成几段,满足任意子集异或和不为0
思路:当序列异或和为0时无解,因为一段的异或和可以用两个前缀异或和求得,我们将每个数异或前缀和处理下扔到线性基里,基底个数就是答案。
实现代码:
#include<bits/stdc++.h>
using namespace std;
#define ll long long
const int M = 1e6+;
struct Linear_Basis{
ll b[],nb[],tot;
void init(){
tot = ;
memset(b,,sizeof(b));
memset(nb,,sizeof(nb));
} bool Insert(ll x){
for(int i = ;i >= ;i --){
if(x&(1LL<<i)){
if(!b[i]){
b[i] = x;
break;
}
x ^= b[i];
}
}
return x > ;
} ll Max(ll x){
ll ret = x;
for(int i = ;i >= ;i --)
ret = max(ret,ret^b[i]);
return ret;
} ll Min(ll x){
ll ret = x;
for(int i = ;i <= ;i ++)
if(b[i]) ret ^= b[i];
return ret;
} void rebuild(){
for(int i = ;i >= ;i --)
for(int j = i-;j >= ;j --)
if(b[i]&(1LL<<j)) b[i]^=b[j];
for(int i = ;i <= ;i ++)
if(b[i]) nb[tot++] = b[i];
} ll K_Min(ll k){
ll res = ;
if(k >= (1LL<<tot))
return -;
for(int i = ;i >= ;i --)
if(k&(1LL<<i))
res ^= nb[i];
return res;
}
}LB; int main(){
int n,x;
cin>>n;
LB.init();
ll ans = ;
for(int i = ;i <= n;i ++){
cin>>x;
ans = ans^x;
LB.Insert(ans);
}
int cnt = ;
if(ans == ) cout<<-<<endl;
else {
for(int i = ;i >= ;i--)
if(LB.b[i]) cnt ++;
printf("%d\n",cnt);
} return ;
}
Educational Codeforces Round 58 A,B,C,D,E,G的更多相关文章
- Educational Codeforces Round 58 (Rated for Div. 2) 题解
Educational Codeforces Round 58 (Rated for Div. 2) 题目总链接:https://codeforces.com/contest/1101 A. Min ...
- Educational Codeforces Round 58 (Rated for Div. 2) F dp + 优化(新坑) + 离线处理
https://codeforces.com/contest/1101/problem/F 题意 有n个城市,m辆卡车,每辆卡车有起点\(s_i\),终点\(f_i\),每公里油耗\(c_i\),可加 ...
- Educational Codeforces Round 58 (Rated for Div. 2) D 树形dp + 数学
https://codeforces.com/contest/1101/problem/D 题意 一颗n个点的树,找出一条gcd>1的最长链,输出长度 题解 容易想到从自底向长转移 因为只需要g ...
- Educational Codeforces Round 58 (Rated for Div. 2) G 线性基
https://codeforces.com/contest/1101/problem/G 题意 一个有n个数字的数组a[],将区间分成尽可能多段,使得段之间的相互组合异或和不等于零 题解 根据线性基 ...
- Educational Codeforces Round 58 Div. 2 自闭记
明明多个几秒就能场上AK了.自闭. A:签到. #include<iostream> #include<cstdio> #include<cmath> #inclu ...
- Educational Codeforces Round 58
D. GCD Counting 题意: 给出n个点的树,每个点有一个权值,找出一条最长的路径使得路径上所有的点的gcd>1 题解: gcd>1的一定不会有很多.所以暴力搞一下就行,不需要点 ...
- Educational Codeforces Round 58 Solution
A. Minimum Integer 签到. #include <bits/stdc++.h> using namespace std; #define ll long long ll l ...
- Educational Codeforces Round 58 (Rated for Div. 2)
A. Minimum Integer 水 #include<bits/stdc++.h> #define clr(a,b) memset(a,b,sizeof(a)) using name ...
- Educational Codeforces Round 58 (Rated for Div. 2) (前两题题解)
感慨 这次比较昏迷最近算法有点飘,都在玩pygame...做出第一题让人hack了,第二题还昏迷想错了 A Minimum Integer(数学) 水题,上来就能做出来但是让人hack成了tle,所以 ...
随机推荐
- Redux 入门教程(三):React-Redux 的用法
为了方便使用,Redux 的作者封装了一个 React 专用的库 React-Redux,本文主要介绍它. 这个库是可以选用的.实际项目中,你应该权衡一下,是直接使用 Redux,还是使用 React ...
- H5 38-背景图片和插入图片区别
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8&quo ...
- poj3984 广度搜索BFS
迷宫问题 Description 定义一个二维数组: int maze[5][5] = { 0, 1, 0, 0, 0, 0, 1, 0, 1, 0, 0, 0, 0, 0, 0, 0, 1, 1 ...
- 使用mysql,sql语言删除冗余信息
这是表,我们需要操作的就是删除除了学号不同,其它信息都相同的冗余信息 思路:删除表格class3中的冗余的stu_id信息,那么接下来我们应该去筛选哪些stu_id信息是冗余的, 此时我们想到的就是利 ...
- C#使用OneNote的图片文字识别功能(OCR)
http://www.cnblogs.com/Charltsing/p/OneNoteOCR.html 有需要技术咨询的,联系QQ564955427 前段时间有人问我能不能通过OneNote扫描图片, ...
- Redis服务端的搭建(初级)
前方低能,仅适合入门级菜鸟阅读,大神大牛通通闪开! 前言:redis经常被用来做缓存(原因自行科普),基于学习的需要自己搭建了一个redis服务器,考虑到项目的分布式部署,所以前期开始的时候,redi ...
- node.js介绍和npm的使用
Node.js介绍 打开Nodejs英文网:https://nodejs.org/en/ 中文网:http://nodejs.cn/ 我们会发现这样一句话: 翻译成中文如下: Node.js 是一个基 ...
- 【学习总结】GirlsInAI ML-diary day-3-数据类型
[学习总结]GirlsInAI ML-diary 总 原博github链接-day3 数据类型 熟悉一下计算时可能碰到的数据类型.(计算时...) 1-打开jupyter,new一个新python文件 ...
- oracle事务的四个特性(ACID)
事务产生的背景 当在PL/SQL中同时操作多个SQL语句,比如通过DML语句添加.修改或删除数据时,如何确保数据库数据不会因为意外而倒置错误数据是一个非常重要的问题. 以仓库发料系统为例,如果某一张领 ...
- Azure系列2.1.13 —— CloudBlockBlob
(小弟自学Azure,文中有不正确之处,请路过各位大神指正.) 网上azure的资料较少,尤其是API,全是英文的,中文资料更是少之又少.这次由于公司项目需要使用Azure,所以对Azure的一些学习 ...