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. Python入门-用户登录程序

    _flag = Falsecount = 0users = [['ziv', '123'], ['alex', '12345']]while count < 3: username = inpu ...

  2. getQueryStringByName url参数/

    MasterId: (masterIdUrl != null && masterIdUrl != "") ? masterIdUrl : null ClassId: ...

  3. Java 异常处理的误区和经验总结

    Java 异常处理的误区和经验总结   1 本文着重介绍了 Java 异常选择和使用中的一些误区,希望各位读者能够熟练掌握异常处理的一些注意点和原则,注意总结和归纳.只有处理好了异常,才能提升开发人员 ...

  4. Redis 安装学习

    Linux下下载安装redis https://redis.io/download tar -zvxf redisxxx cd redisxxxx make  ---进行安装 vim ~.bash_p ...

  5. 日期选择器date、week、time、datetime、datetime-local类型

    下面只写两个类型的代码案例,其他都大同小异 date类型: <!DOCTYPE html> <html> <head> <meta charset=" ...

  6. CRM系统数据授权

    1.新建角色,华东二区 2.业务对象中找到客户管理 3.在数据范围中新建数据规则,并进行设置 4.点击授权后,生效. 另:数据权限设置

  7. redis设置防火墙的问题

    Linux 下载安装配置Redis完整步骤   安装: 1.获取redis资源 wget http://download.redis.io/releases/redis-4.0.8.tar.gz 2. ...

  8. springboot No Identifier specified for entity的解决办法

    今天在做一个项目的时候遇到一个问题,实体类忘了指定主键id,然后报如下错误,也是自己粗心大意造成的,在此记录下. java.lang.IllegalStateException: Failed to ...

  9. python学习笔记(2)--基本语法元素

    来看一个非常简单的温度转换程序 #Tempconvert.py tempstr = input("输入:") if tempstr[-1] in ['F', 'f']: C = ( ...

  10. 用python写一个预警机器人(支持微信和钉钉)

    背景 线上的系统在运行中,发生故障时怎么及时的通过手机通知到相关人员?当然这是个很简单的需求,现有的方法有很多,例如: 如果我们用的云产品,那么一般都会有配套对应的监控预警功能,根据需要配置一下即可, ...