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. 牛客练习赛38 D 出题人的手环

    链接 [https://ac.nowcoder.com/acm/contest/358/D] 题意 链接:https://ac.nowcoder.com/acm/contest/358/D 来源:牛客 ...

  2. HTTP协议,Http 常用状态码

    一.HTTP协议-Request   HTTP报文是面向文本的,报文中的每一个字段都是一些ASCII码串,各个字段的长度是不确定的.HTTP有两类报文:请求报文和响应报文.   1.1 HTTP请求报 ...

  3. python 中的re模块,正则表达式

    一.re模块 re模块中常用的方法. match: 默认从字符串开头开始匹配,re.match('fun', 'funny') 可以匹配出来 'fun' match(pattern, string, ...

  4. 福州大学软件工程1816 | W班 第10次作业[软件工程实践总结]

    作业链接 个人作业--软件工程实践总结 评分细则 本次由五个问题(每个十分)+创意照片(五分)+附加题(十分)组成 评分统计图 千帆竞发图 汇总成绩排名链接 汇总链接

  5. MySQL左连接时 返回的记录条数 比 左边表 数量多

    在学MySQL的连接时,为了便于记忆,就将左连接 记做 最后结果的总记录数 和 进行左连接的左表的记录数相同,简单的说就是下面这个公式 count(table A left join table B) ...

  6. Python&R&量化 金融之路

    [ 分类 ]- 金融之路 - 闲云孤鹤(人生在世五十年,大千世界一瞬间,浮生若梦,仿佛间,幻境一场,生者无常,终须尽.) - CSDN博客 https://blog.csdn.net/robertso ...

  7. Azure系列2.1.5 —— BlobOutputStream

    (小弟自学Azure,文中有不正确之处,请路过各位大神指正.) 网上azure的资料较少,尤其是API,全是英文的,中文资料更是少之又少.这次由于公司项目需要使用Azure,所以对Azure的一些学习 ...

  8. Chrome 离线安装插件的办法

    参考url 学习网址 https://blog.csdn.net/weixin_39068791/article/details/81411938 插件下载地址: http://www.lanfans ...

  9. ES6/ES2015的一些特性的简单使

    1.一些常用的ES6的特性: let, const, class, extends, super, arrow functions, template string, destructuring, d ...

  10. 6s ios9.0平台 微信小程序的fixed定位兼容性问题

    如果不设置top和left的话  就会出现不显示问题