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的更多相关文章

  1. Educational Codeforces Round 58 (Rated for Div. 2) 题解

    Educational Codeforces Round 58 (Rated for Div. 2)  题目总链接:https://codeforces.com/contest/1101 A. Min ...

  2. 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\),可加 ...

  3. Educational Codeforces Round 58 (Rated for Div. 2) D 树形dp + 数学

    https://codeforces.com/contest/1101/problem/D 题意 一颗n个点的树,找出一条gcd>1的最长链,输出长度 题解 容易想到从自底向长转移 因为只需要g ...

  4. Educational Codeforces Round 58 (Rated for Div. 2) G 线性基

    https://codeforces.com/contest/1101/problem/G 题意 一个有n个数字的数组a[],将区间分成尽可能多段,使得段之间的相互组合异或和不等于零 题解 根据线性基 ...

  5. Educational Codeforces Round 58 Div. 2 自闭记

    明明多个几秒就能场上AK了.自闭. A:签到. #include<iostream> #include<cstdio> #include<cmath> #inclu ...

  6. Educational Codeforces Round 58

    D. GCD Counting 题意: 给出n个点的树,每个点有一个权值,找出一条最长的路径使得路径上所有的点的gcd>1 题解: gcd>1的一定不会有很多.所以暴力搞一下就行,不需要点 ...

  7. Educational Codeforces Round 58 Solution

    A. Minimum Integer 签到. #include <bits/stdc++.h> using namespace std; #define ll long long ll l ...

  8. 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 ...

  9. Educational Codeforces Round 58 (Rated for Div. 2) (前两题题解)

    感慨 这次比较昏迷最近算法有点飘,都在玩pygame...做出第一题让人hack了,第二题还昏迷想错了 A Minimum Integer(数学) 水题,上来就能做出来但是让人hack成了tle,所以 ...

随机推荐

  1. RabbitMQ总结

    消息队列 三个业务场景:解耦.异步.削峰 带来问题 系统可用性降低:外部依赖越多,越容易挂掉. 系统复杂性提高:重复消费,消息丢失,消息传递的顺序性 一致性问题: 一.如何保证消息的可靠性传输(如何处 ...

  2. 关于always块内for循环的执行方式

    //该模块主要用来说明for结构在时序逻辑中的执行方式 :] eq_dly ); integer i; 'b1; always @(posedge clk_1 or negedge nrst) beg ...

  3. es6在网页中模块引入的方法

    前言: 以前,当然包括现在的大部分js引入,我们都是利用<script></script>这种全局的方式进行引入,当然这种弊端还是用的,比如这样直接利用script引入的话,会 ...

  4. pdf转eps后存在大片空白的处理

    之前pdf转eps的方式是用acrobat直接转,发现每次转完后,图片都显示在一张A4纸上,插入到论文中时会出现大片空白:但在pdf中是没有这么多空白的,与裁剪没关系. 后来在 http://tex. ...

  5. 解决远程连接mysql很慢的方法(网络正常)

    最近用mysql命令行或者JDBC远程连接mysql速度很慢,而且远大于ping时间.上网搜了一下,解决方案如下: 在/etc/mysql/my.cnf文件的[mysqld]部分加入:skip-nam ...

  6. 团队作业5——测试与发布(alpha阶段)

    Deadline: 2018-5-9 10:00PM,以提交至班级博客时间为准. 根据以下要求,完成对本团队项目的测试与发布. 测试 请根据团队项目中软件的需求文档.功能说明.系统设计和测试计划,写出 ...

  7. mysql cpu 100% 满 优化方案

    解决MySQL CPU占用100%的经验总结 - karl_han的专栏 - CSDN博客 https://blog.csdn.net/karl_han/article/details/5630782 ...

  8. Yii2几个要注意的小地方

    本人新手, 刚接触Yii, 记录下遇到的坑, 大神请绕道/ 1. //插入数据到数据库, 需要 new 一下,设置属性: $info = new BasicInfo(); $info -> se ...

  9. Ajax发送请求等待时弹出模态框等待提示

    主要的代码分为两块,一个是CSS定义模态框,另一个是在Ajax中弹出模态框. 查看菜鸟教程中的模态框教程demo,http://www.runoob.com/try/try.php?filename= ...

  10. 当mysql报错1045时的解决方法

    2.用记事本打开 添加 打开后,搜索mysqld关键字 找到后,在mysqld下面添加skip-grant-tables,保存退出. 如果保存在了c盘里不能修改那么就采用这样的方法 然后就可以修改c盘 ...