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,所以 ...
随机推荐
- Vue(四)之webpack和vue-cli
01-webpack介绍 官方文档:https://www.webpackjs.com/concepts/ 本质上,webpack 是一个现代 JavaScript 应用程序的静态模块打包器(modu ...
- WinForm 进度条
using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; usin ...
- 计算Java List中的重复项出现次数
import java.util.ArrayList;import java.util.HashMap;import java.util.Iterator;import java.util.List; ...
- 18-vue-cli脚手架项目中组件的使用
在webpack-simple模板中,包括webpck模板.一个.vue文件就是一个组件. 为什么会这样呢?因为webpack干活了!webpack的将我们所有的资源文件进行打包.同时webpack还 ...
- # 【Python3练习题 003】一个整数,它加上100后是一个完全平方数,再加上168又是一个完全平方数,请问该数是多少?
# -------------------------------------------------## 所谓的“完全平方数”,就是开完根号仍然是整数.## 数学渣是这么思考的:假设这个数 i 在1 ...
- js上传视频(jquery.form.js)
// 上传目标触发点 <input type="file" class="upvideo" name="upvideo" id=&qu ...
- gulp项目和webpack项目在浏览器中查看的方式
在存在.git的目录下,按住shift+左键,打开命令行或者使用git Bash Gulp: 输入gulp dev 本地起一个服务器,在项目中找到gulp.js,然后找本地服务器,找到host和por ...
- 5 Http请求中文乱码处理
java 乱码分很多种,这里主要研究解决http请求中出现乱码的情况. http请求出现中文乱码的主要原因:发送方与接收方编码不一致,服务器默认支持的编码与web应用不一致,如:tomcat 是国外程 ...
- Java 简单的登录验证码
1 验证码的作用 验证码是为了区分人与机器,如果没有验证码机制,web网站或者应用会遇到很多问题,具体如下: ① 网站容易被暴力登录攻破密码,可以制作一个自动程序不断的尝试登录,密码很容易被破解,系统 ...
- CMake--变量
1.一般变量 1)CMake变量引用的方式 使用${}进行变量的引用.例如: ${PROJECT_NAME} #返回项目名称 在 IF 等语句中,是直接使用变量名而不通过${}取值. 2)cmake自 ...