Codeforces Round #400
最近好像总是有点不想打,专题也刷不动,还是坚持这做了一场,虽然打到一半就没打了。。。(反正通常都只能做出两题)
感觉自己切水题越来越熟练了,然而难题还是不会做。。
A题,水,用vector存下来就行了
- #include<map>
- #include<set>
- #include<cmath>
- #include<queue>
- #include<stack>
- #include<vector>
- #include<cstdio>
- #include<cassert>
- #include<iomanip>
- #include<cstdlib>
- #include<cstring>
- #include<iostream>
- #include<algorithm>
- #define pi acos(-1)
- #define ll long long
- #define mod 1000000007
- #define ls l,m,rt<<1
- #define rs m+1,r,rt<<1|1
- #pragma comment(linker, "/STACK:1024000000,1024000000")
- using namespace std;
- const double g=10.0,eps=1e-;
- const int N=+,maxn=+,inf=0x3f3f3f;
- int main()
- {
- ios::sync_with_stdio(false);
- cin.tie();
- string la,lb;
- cin>>la>>lb;
- vector<pair<string,string> >v;
- v.push_back(make_pair(la,lb));
- int n;
- cin>>n;
- for(int i=;i<n;i++)
- {
- string a,b;
- cin>>a>>b;
- if(a==la)
- {
- v.push_back(make_pair(lb,b));
- la=lb,lb=b;
- }
- else
- {
- v.push_back(make_pair(la,b));
- la=la,lb=b;
- }
- }
- for(int i=;i<v.size();i++)
- cout<<v[i].first<<" "<<v[i].second<<endl;
- return ;
- }
A
B题,很水的染色问题,如果,一个数是另一个数 的素因子,那么这两个数染的色不能相同,刚开始因为是因子wa了一发
- #include<map>
- #include<set>
- #include<cmath>
- #include<queue>
- #include<stack>
- #include<vector>
- #include<cstdio>
- #include<cassert>
- #include<iomanip>
- #include<cstdlib>
- #include<cstring>
- #include<iostream>
- #include<algorithm>
- #define pi acos(-1)
- #define ll long long
- #define mod 1000000007
- #define ls l,m,rt<<1
- #define rs m+1,r,rt<<1|1
- #pragma comment(linker, "/STACK:1024000000,1024000000")
- using namespace std;
- const double g=10.0,eps=1e-;
- const int N=+,maxn=+,inf=0x3f3f3f;
- int color[N];
- bool vis[N];
- void prime()
- {
- memset(color,,sizeof color);
- memset(vis,,sizeof vis);
- for(int i=;i<N;i++)
- {
- if(vis[i]==)
- {
- int k=;
- color[i]=;
- for(int j=*i;j<N;j+=i)
- {
- vis[j]=;
- if(color[j]==)color[j]=;
- }
- }
- }
- }
- int main()
- {
- ios::sync_with_stdio(false);
- cin.tie();
- prime();
- int n;
- cin>>n;
- set<int>ans;
- for(int i=;i<=n+;i++)
- ans.insert(color[i]);
- cout<<ans.size()<<endl;
- for(int i=;i<=n+;i++)
- cout<<color[i]<<" ";
- return ;
- }
B
C题,先求出前缀和,然后就有sum[i]-k^t=sum[j],把sum[i]用map存起来,然后枚举k^t看sum[i]-k^t是不是在map中,要边加边存,如果全部存起来再算的话会wa,我也不知道是为什么。。
- #include<map>
- #include<set>
- #include<cmath>
- #include<queue>
- #include<stack>
- #include<vector>
- #include<cstdio>
- #include<cassert>
- #include<iomanip>
- #include<cstdlib>
- #include<cstring>
- #include<iostream>
- #include<algorithm>
- #define pi acos(-1)
- #define ll long long
- #define mod 1000000007
- #define ls l,m,rt<<1
- #define rs m+1,r,rt<<1|1
- #pragma comment(linker, "/STACK:1024000000,1024000000")
- using namespace std;
- const double g=10.0,eps=1e-;
- const int N=+,maxn=+,inf=0x3f3f3f;
- ll a[N];
- int main()
- {
- ios::sync_with_stdio(false);
- cin.tie();
- ll n,k;
- cin>>n>>k;
- for(ll i=;i<=n;i++)cin>>a[i];
- map<ll,ll>m;
- m[]=;
- for(ll i=;i<=n;i++)a[i]+=a[i-];
- ll ans=;
- set<ll>s;
- set<ll>::iterator j;
- for(ll i=;i<;i++)
- {
- if(pow(k,i)>1e14||pow(k,i)<-1e14)break;
- s.insert((ll)pow(k,i));
- }
- for(ll i=;i<=n;i++)
- {
- for(j=s.begin();j!=s.end();j++)
- ans+=m[a[i]-*j];
- m[a[i]]++;
- }
- cout<<ans<<endl;
- return ;
- }
C
D题,2-sat没学啊,那就并查集吧,分成两棵树
如果门是开的,则2个开关要么都关要么都开,Merge(d[i][0],d[i][1]),Merge(d[i][0]+m,d[i][1]+m);
否则只开其中一个, Merge(d[i][0]+m,d[i][1]),Merge(d[i][0],d[i][1]+m);
最后扫一遍并查集,如果 存在至少一个开关的点 i 和 i+m处在同一颗树上,则开关即开有关,相矛盾,故不存在可行方案,否则存在。
- #include<map>
- #include<set>
- #include<cmath>
- #include<queue>
- #include<stack>
- #include<vector>
- #include<cstdio>
- #include<cassert>
- #include<iomanip>
- #include<cstdlib>
- #include<cstring>
- #include<iostream>
- #include<algorithm>
- #define pi acos(-1)
- #define ll long long
- #define mod 1000000007
- #define ls l,m,rt<<1
- #define rs m+1,r,rt<<1|1
- #pragma comment(linker, "/STACK:1024000000,1024000000")
- using namespace std;
- const double g=10.0,eps=1e-;
- const int N=+,maxn=+,inf=0x3f3f3f;
- int father[N*],a[N];
- vector<int>d[N];
- inline int Find(int x)
- {
- if(x!=father[x])
- {
- father[x]=Find(father[x]);
- }
- return father[x];
- }
- void Merge(int x,int y)
- {
- x=Find(x);
- y=Find(y);
- father[x]=y;
- }
- int main()
- {
- ios::sync_with_stdio(false);
- cin.tie();
- int n,m;
- cin>>n>>m;
- for(int i=;i<*m;i++)father[i]=i;
- for(int i=;i<=n;i++)cin>>a[i];
- for(int i=;i<m;)
- {
- int x;
- cin>>x;
- for(int j=;j<x;j++)
- {
- int p;
- cin>>p;
- d[p].push_back(i);
- }
- if(!x)--m;
- else i++;
- }
- for(int i=;i<=n;i++)
- {
- if(a[i])Merge(d[i][],d[i][]),Merge(d[i][]+m,d[i][]+m);
- else Merge(d[i][]+m,d[i][]),Merge(d[i][],d[i][]+m);
- }
- for(int i=;i<m;i++)
- {
- if(Find(i)==Find(i+m))
- {
- cout<<"NO"<<endl;
- return ;
- }
- }
- cout<<"YES"<<endl;
- return ;
- }
D
Codeforces Round #400的更多相关文章
- ICM Technex 2017 and Codeforces Round #400 (Div. 1 + Div. 2, combined) D. The Door Problem 2-SAT
题目链接:http://codeforces.com/contest/776/problem/D D. The Door Problem time limit per test 2 seconds m ...
- ICM Technex 2017 and Codeforces Round #400 (Div. 1 + Div. 2, combined) A map B贪心 C思路前缀
A. A Serial Killer time limit per test 2 seconds memory limit per test 256 megabytes input standard ...
- ICM Technex 2017 and Codeforces Round #400 (Div. 1 + Div. 2, combined) A
Our beloved detective, Sherlock is currently trying to catch a serial killer who kills a person each ...
- ICM Technex 2017 and Codeforces Round #400 (Div. 1 + Div. 2, combined)
前四题比较水,E我看出是欧拉函数傻逼题,但我傻逼不会,百度了下开始学,最后在加时的时候A掉了 AC:ABCDE Rank:182 Rating:2193+34->2227 终于橙了,不知道能待几 ...
- 【2-SAT】【并查集】ICM Technex 2017 and Codeforces Round #400 (Div. 1 + Div. 2, combined) D. The Door Problem
再来回顾一下2-SAT,把每个点拆点为是和非两个点,如果a能一定推出非b,则a->非b,其他情况同理. 然后跑强连通分量分解,保证a和非a不在同一个分量里面. 这题由于你建完图发现都是双向边,所 ...
- 【枚举】【前缀和】【map】ICM Technex 2017 and Codeforces Round #400 (Div. 1 + Div. 2, combined) C. Molly's Chemicals
处理出前缀和,枚举k的幂,然后从前往后枚举,把前面的前缀和都塞进map,可以方便的查询对于某个右端点,有多少个左端点满足该段区间的和为待查询的值. #include<cstdio> #in ...
- ICM Technex 2017 and Codeforces Round #400 (Div. 1 + Div. 2, combined) D
Moriarty has trapped n people in n distinct rooms in a hotel. Some rooms are locked, others are unlo ...
- ICM Technex 2017 and Codeforces Round #400 (Div. 1 + Div. 2, combined) C
Molly Hooper has n different kinds of chemicals arranged in a line. Each of the chemicals has an aff ...
- ICM Technex 2017 and Codeforces Round #400 (Div. 1 + Div. 2, combined) B
Sherlock has a new girlfriend (so unlike him!). Valentine's day is coming and he wants to gift her s ...
随机推荐
- 详解MySQL第二篇—DML语句
DML 语句: DML 操作是指对数据库中表记录的操作,主要包括表记录的插入(insert).更新(update).删除(delete)和查(select),是开发人员日常使用最频繁的操作.下面将依次 ...
- SCADA 必备函数之 :关于消息的函数
Message Functions BroadcastSystemMessage//是将一条系统消息广播给系统中所有的顶级窗口. BroadcastSystemMessageEx//将消息发送到指定的 ...
- ViewFlipper
main.xml <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" xml ...
- java Object转换成指定的类型
java Object转换成指定的类型 /** * Object转成指定的类型 * @param obj * @param type * @param <T> * @return */ p ...
- JavaScript-dom4 date string 事件绑定
内置date <!DOCTYPE html> <html lang="en"> <head> <meta charset="UT ...
- C++之旅(第一天)
基础知识 完全支持C语言 可以在C++引入C的头文件 #include <stdio.h> #include <iostream> int main() { } 输入和输出 C ...
- motan rpc
git : 帮助 文档 基本介绍 Motan是一套基于java开发的RPC框架,除了常规的点对点调用外,Motan还提供服务治理功能,包括服务节点的自动发现.摘除.高可用和负载均衡等.Motan具有 ...
- ES6 利用 Set 数组去重法
例子: const set = new Set(); [2, 3, 5, 4, 5, 2, 2].forEach(x => set.add(x) ); const arr = [...set]; ...
- java反射 - getXXX 与 getDeclaredXXX
1.getXXX 和 getDeclaredXXX java 里 Class<?> 有下面这些方法: 类似的方法有: 2.getMethod(s) 和 getDeclaredMethod( ...
- asp.net操作GridView添删改查的两种方法 及 光棒效果
这部份小内容很想写下来了,因为是基础中的基础,但是近来用的比较少,又温习了一篇,发现有点陌生了,所以,还是写一下吧. 方法一:使用Gridview本身自带的事件处理,代码如下(注意:每次操作完都得重新 ...