最近好像总是有点不想打,专题也刷不动,还是坚持这做了一场,虽然打到一半就没打了。。。(反正通常都只能做出两题)

感觉自己切水题越来越熟练了,然而难题还是不会做。。

A题,水,用vector存下来就行了

  1. #include<map>
  2. #include<set>
  3. #include<cmath>
  4. #include<queue>
  5. #include<stack>
  6. #include<vector>
  7. #include<cstdio>
  8. #include<cassert>
  9. #include<iomanip>
  10. #include<cstdlib>
  11. #include<cstring>
  12. #include<iostream>
  13. #include<algorithm>
  14. #define pi acos(-1)
  15. #define ll long long
  16. #define mod 1000000007
  17. #define ls l,m,rt<<1
  18. #define rs m+1,r,rt<<1|1
  19. #pragma comment(linker, "/STACK:1024000000,1024000000")
  20.  
  21. using namespace std;
  22.  
  23. const double g=10.0,eps=1e-;
  24. const int N=+,maxn=+,inf=0x3f3f3f;
  25.  
  26. int main()
  27. {
  28. ios::sync_with_stdio(false);
  29. cin.tie();
  30. string la,lb;
  31. cin>>la>>lb;
  32. vector<pair<string,string> >v;
  33. v.push_back(make_pair(la,lb));
  34. int n;
  35. cin>>n;
  36. for(int i=;i<n;i++)
  37. {
  38. string a,b;
  39. cin>>a>>b;
  40. if(a==la)
  41. {
  42. v.push_back(make_pair(lb,b));
  43. la=lb,lb=b;
  44. }
  45. else
  46. {
  47. v.push_back(make_pair(la,b));
  48. la=la,lb=b;
  49. }
  50. }
  51. for(int i=;i<v.size();i++)
  52. cout<<v[i].first<<" "<<v[i].second<<endl;
  53. return ;
  54. }

A

B题,很水的染色问题,如果,一个数是另一个数 的素因子,那么这两个数染的色不能相同,刚开始因为是因子wa了一发

  1. #include<map>
  2. #include<set>
  3. #include<cmath>
  4. #include<queue>
  5. #include<stack>
  6. #include<vector>
  7. #include<cstdio>
  8. #include<cassert>
  9. #include<iomanip>
  10. #include<cstdlib>
  11. #include<cstring>
  12. #include<iostream>
  13. #include<algorithm>
  14. #define pi acos(-1)
  15. #define ll long long
  16. #define mod 1000000007
  17. #define ls l,m,rt<<1
  18. #define rs m+1,r,rt<<1|1
  19. #pragma comment(linker, "/STACK:1024000000,1024000000")
  20.  
  21. using namespace std;
  22.  
  23. const double g=10.0,eps=1e-;
  24. const int N=+,maxn=+,inf=0x3f3f3f;
  25.  
  26. int color[N];
  27. bool vis[N];
  28. void prime()
  29. {
  30. memset(color,,sizeof color);
  31. memset(vis,,sizeof vis);
  32. for(int i=;i<N;i++)
  33. {
  34. if(vis[i]==)
  35. {
  36. int k=;
  37. color[i]=;
  38. for(int j=*i;j<N;j+=i)
  39. {
  40. vis[j]=;
  41. if(color[j]==)color[j]=;
  42. }
  43. }
  44. }
  45. }
  46. int main()
  47. {
  48. ios::sync_with_stdio(false);
  49. cin.tie();
  50. prime();
  51. int n;
  52. cin>>n;
  53. set<int>ans;
  54. for(int i=;i<=n+;i++)
  55. ans.insert(color[i]);
  56. cout<<ans.size()<<endl;
  57. for(int i=;i<=n+;i++)
  58. cout<<color[i]<<" ";
  59. return ;
  60. }

B

C题,先求出前缀和,然后就有sum[i]-k^t=sum[j],把sum[i]用map存起来,然后枚举k^t看sum[i]-k^t是不是在map中,要边加边存,如果全部存起来再算的话会wa,我也不知道是为什么。。

  1. #include<map>
  2. #include<set>
  3. #include<cmath>
  4. #include<queue>
  5. #include<stack>
  6. #include<vector>
  7. #include<cstdio>
  8. #include<cassert>
  9. #include<iomanip>
  10. #include<cstdlib>
  11. #include<cstring>
  12. #include<iostream>
  13. #include<algorithm>
  14. #define pi acos(-1)
  15. #define ll long long
  16. #define mod 1000000007
  17. #define ls l,m,rt<<1
  18. #define rs m+1,r,rt<<1|1
  19. #pragma comment(linker, "/STACK:1024000000,1024000000")
  20.  
  21. using namespace std;
  22.  
  23. const double g=10.0,eps=1e-;
  24. const int N=+,maxn=+,inf=0x3f3f3f;
  25.  
  26. ll a[N];
  27. int main()
  28. {
  29. ios::sync_with_stdio(false);
  30. cin.tie();
  31. ll n,k;
  32. cin>>n>>k;
  33. for(ll i=;i<=n;i++)cin>>a[i];
  34. map<ll,ll>m;
  35. m[]=;
  36. for(ll i=;i<=n;i++)a[i]+=a[i-];
  37. ll ans=;
  38. set<ll>s;
  39. set<ll>::iterator j;
  40. for(ll i=;i<;i++)
  41. {
  42. if(pow(k,i)>1e14||pow(k,i)<-1e14)break;
  43. s.insert((ll)pow(k,i));
  44. }
  45. for(ll i=;i<=n;i++)
  46. {
  47. for(j=s.begin();j!=s.end();j++)
  48. ans+=m[a[i]-*j];
  49. m[a[i]]++;
  50. }
  51. cout<<ans<<endl;
  52. return ;
  53. }

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处在同一颗树上,则开关即开有关,相矛盾,故不存在可行方案,否则存在。

  1. #include<map>
  2. #include<set>
  3. #include<cmath>
  4. #include<queue>
  5. #include<stack>
  6. #include<vector>
  7. #include<cstdio>
  8. #include<cassert>
  9. #include<iomanip>
  10. #include<cstdlib>
  11. #include<cstring>
  12. #include<iostream>
  13. #include<algorithm>
  14. #define pi acos(-1)
  15. #define ll long long
  16. #define mod 1000000007
  17. #define ls l,m,rt<<1
  18. #define rs m+1,r,rt<<1|1
  19. #pragma comment(linker, "/STACK:1024000000,1024000000")
  20.  
  21. using namespace std;
  22.  
  23. const double g=10.0,eps=1e-;
  24. const int N=+,maxn=+,inf=0x3f3f3f;
  25.  
  26. int father[N*],a[N];
  27. vector<int>d[N];
  28. inline int Find(int x)
  29. {
  30. if(x!=father[x])
  31. {
  32. father[x]=Find(father[x]);
  33. }
  34. return father[x];
  35. }
  36. void Merge(int x,int y)
  37. {
  38. x=Find(x);
  39. y=Find(y);
  40. father[x]=y;
  41. }
  42. int main()
  43. {
  44. ios::sync_with_stdio(false);
  45. cin.tie();
  46. int n,m;
  47. cin>>n>>m;
  48. for(int i=;i<*m;i++)father[i]=i;
  49. for(int i=;i<=n;i++)cin>>a[i];
  50. for(int i=;i<m;)
  51. {
  52. int x;
  53. cin>>x;
  54. for(int j=;j<x;j++)
  55. {
  56. int p;
  57. cin>>p;
  58. d[p].push_back(i);
  59. }
  60. if(!x)--m;
  61. else i++;
  62. }
  63. for(int i=;i<=n;i++)
  64. {
  65. if(a[i])Merge(d[i][],d[i][]),Merge(d[i][]+m,d[i][]+m);
  66. else Merge(d[i][]+m,d[i][]),Merge(d[i][],d[i][]+m);
  67. }
  68. for(int i=;i<m;i++)
  69. {
  70. if(Find(i)==Find(i+m))
  71. {
  72. cout<<"NO"<<endl;
  73. return ;
  74. }
  75. }
  76. cout<<"YES"<<endl;
  77. return ;
  78. }

D

Codeforces Round #400的更多相关文章

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

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

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

  4. ICM Technex 2017 and Codeforces Round #400 (Div. 1 + Div. 2, combined)

    前四题比较水,E我看出是欧拉函数傻逼题,但我傻逼不会,百度了下开始学,最后在加时的时候A掉了 AC:ABCDE Rank:182 Rating:2193+34->2227 终于橙了,不知道能待几 ...

  5. 【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不在同一个分量里面. 这题由于你建完图发现都是双向边,所 ...

  6. 【枚举】【前缀和】【map】ICM Technex 2017 and Codeforces Round #400 (Div. 1 + Div. 2, combined) C. Molly's Chemicals

    处理出前缀和,枚举k的幂,然后从前往后枚举,把前面的前缀和都塞进map,可以方便的查询对于某个右端点,有多少个左端点满足该段区间的和为待查询的值. #include<cstdio> #in ...

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

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

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

随机推荐

  1. 详解MySQL第二篇—DML语句

    DML 语句: DML 操作是指对数据库中表记录的操作,主要包括表记录的插入(insert).更新(update).删除(delete)和查(select),是开发人员日常使用最频繁的操作.下面将依次 ...

  2. SCADA 必备函数之 :关于消息的函数

    Message Functions BroadcastSystemMessage//是将一条系统消息广播给系统中所有的顶级窗口. BroadcastSystemMessageEx//将消息发送到指定的 ...

  3. ViewFlipper

    main.xml <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" xml ...

  4. java Object转换成指定的类型

    java Object转换成指定的类型 /** * Object转成指定的类型 * @param obj * @param type * @param <T> * @return */ p ...

  5. JavaScript-dom4 date string 事件绑定

    内置date <!DOCTYPE html> <html lang="en"> <head> <meta charset="UT ...

  6. C++之旅(第一天)

    基础知识 完全支持C语言 可以在C++引入C的头文件 #include <stdio.h> #include <iostream> int main() { } 输入和输出 C ...

  7. motan rpc

    git :  帮助 文档 基本介绍 Motan是一套基于java开发的RPC框架,除了常规的点对点调用外,Motan还提供服务治理功能,包括服务节点的自动发现.摘除.高可用和负载均衡等.Motan具有 ...

  8. ES6 利用 Set 数组去重法

    例子: const set = new Set(); [2, 3, 5, 4, 5, 2, 2].forEach(x => set.add(x) ); const arr = [...set]; ...

  9. java反射 - getXXX 与 getDeclaredXXX

    1.getXXX 和 getDeclaredXXX java 里 Class<?> 有下面这些方法: 类似的方法有: 2.getMethod(s) 和 getDeclaredMethod( ...

  10. asp.net操作GridView添删改查的两种方法 及 光棒效果

    这部份小内容很想写下来了,因为是基础中的基础,但是近来用的比较少,又温习了一篇,发现有点陌生了,所以,还是写一下吧. 方法一:使用Gridview本身自带的事件处理,代码如下(注意:每次操作完都得重新 ...