感觉自己有点强迫症  不都写出来就找理由不写题解

http://codeforces.com/contest/1015   题目链接

A. Points in Segments

题目意思  n个线段 去覆盖1-m 中的点 问你没有覆盖的点的个数和位置

这个数据很小,可以直接暴力查找

思考:如果n<1e6, m<=1e8 呢?

  1. #include<bits/stdc++.h>
  2. #define int long long
  3. #define MAX(a,b,c) max(a,max(b,c))
  4. #define MIN(a,b,c) min(a,min(b,c))
  5. #define pb push_back
  6. #define fi first
  7. #define se second
  8. typedef long long ll;
  9. typedef long long LL;
  10. typedef unsigned long long ull;
  11. typedef unsigned long long uLL;
  12. using namespace std;
  13. const int maxn=1e5+;
  14. const int INF=0x3f3f3f3f;
  15. map<int,int> mp;
  16. int32_t main()
  17. {
  18. int n,m;
  19. cin>>n>>m;
  20. for(int i=;i<=n;i++)
  21. {
  22. int a,b; cin>>a>>b;
  23. for(int j=a;j<=b;j++)
  24. mp[j]=;
  25. }
  26. int t=;
  27. for(int i=;i<=m;i++)
  28. {
  29. if(mp[i]==)
  30. {
  31. t++;
  32. }
  33. }cout<<t<<endl;
  34. for(int i=;i<=m;i++)
  35. {
  36. if(mp[i]==)
  37. {
  38. cout<<i<<" ";
  39. }
  40. }
  41. }

A.cpp

如果 m<=1e8的 话,可以标记 线段的起点 重点后一位     左右搜一遍

如1-5   a[1]=1; a[6]=-1;

B. Obtaining the String

一个n,两个字符串(ss,tt),左右移动前一个字符串 使两个字符串相等  求最小移动次数;

对比 ss ,tt 当ss[i] !=tt[i]; 在ss[i]后面找和tt[i]一样的, 移动到ss[i];没有就输出-1;

  1. #include<bits/stdc++.h>
  2. #define int long long
  3. #define MAX(a,b,c) max(a,max(b,c))
  4. #define MIN(a,b,c) min(a,min(b,c))
  5. #define pb push_back
  6. #define fi first
  7. #define se second
  8. typedef long long ll;
  9. typedef long long LL;
  10. typedef unsigned long long ull;
  11. typedef unsigned long long uLL;
  12. using namespace std;
  13. const int maxn=1e5+;
  14. const int INF=0x3f3f3f3f;
  15. map<int,int> mp;
  16. vector<int> pp;
  17. int32_t main()
  18. {
  19. int n; cin>>n;
  20. string ss,tt; cin>>ss; cin>>tt;
  21. //if(ss==tt) { cout<<-1<<endl; return 0;}
  22. int j=;
  23. for(int i=;i<n;i++)
  24. {
  25. if(ss[j]==tt[i])
  26. {
  27. j++; continue;
  28. }
  29. int t=;
  30. for(int k=j+;k<n;k++)
  31. {
  32.  
  33. if(ss[k]==tt[i])
  34. {
  35. for(int x=k-;x>=j;x--)
  36. {
  37. swap(ss[x],ss[x+]);
  38. t=;
  39. pp.push_back(x+);
  40. }
  41. if(t==) { j++;break;}
  42. }
  43. }
  44. if(t==) { cout<<-<<endl; return ;}
  45. }
  46. cout<<pp.size()<<endl;
  47. for(int i=;i<pp.size();i++)
  48. {
  49. cout<<pp[i]<<" ";
  50. }
  51. }

B.cpp

C. Songs Compression

n 组数据 一开始的歌曲数据大小  压缩后的数据大小, 要是数据小于等于m;

直接计算一开始的大小,每次减去 差值最大的;看多少次后数据小于等于m; 压缩不到m就输出-1;

  1. #include<bits/stdc++.h>
  2. #define int long long
  3. #define MAX(a,b,c) max(a,max(b,c))
  4. #define MIN(a,b,c) min(a,min(b,c))
  5. #define pb push_back
  6. #define fi first
  7. #define se second
  8. typedef long long ll;
  9. typedef long long LL;
  10. typedef unsigned long long ull;
  11. typedef unsigned long long uLL;
  12. using namespace std;
  13. const int maxn=1e5+;
  14. const int INF=0x3f3f3f3f;
  15. int a[maxn];
  16. int b[maxn];
  17. int d[maxn];
  18. int32_t main()
  19. {
  20. int n,m; cin>>n>>m; int ans1=; int ans2=;
  21. for(int i=;i<=n;i++)
  22. {
  23. cin>>a[i]>>b[i];
  24. d[i]=a[i]-b[i];
  25. ans1+=a[i];
  26. ans2+=b[i];
  27. }
  28. if(ans2>m) { cout<<-<<endl;return ;}
  29. //if(ans1<=m) { cout<<0<<endl;return 0;}
  30. sort(d+,d++n); int t=;
  31. for(int i=n;i>=;i--)
  32. {
  33. if(ans1<=m) break;
  34. ans1=ans1-d[i];
  35. t++;
  36. }
  37. cout<<t<<endl;
  38. }

C.cpp

D. Walking Between Houses

在1-n 中走 k次(随你走到哪,不能不走) 使走的路程为 s;

在保证每次都至少走一步的情况下 先走最大的 1 - n- 1 - n -1 -n....;

最后再每次走一步;

10 9 45 来说 每次走的距离为 9 9 9 9 5 1 1 1 1;

  1. #include<bits/stdc++.h>
  2. #define int long long
  3. #define MAX(a,b,c) max(a,max(b,c))
  4. #define MIN(a,b,c) min(a,min(b,c))
  5. #define pb push_back
  6. #define fi first
  7. #define se second
  8. typedef long long ll;
  9. typedef long long LL;
  10. typedef unsigned long long ull;
  11. typedef unsigned long long uLL;
  12. using namespace std;
  13. const int maxn=1e5+;
  14. const int INF=0x3f3f3f3f;
  15. int32_t main()
  16. {
  17. int n,k,s; cin>>n>>k>>s;
  18. if(s>(n-)*k||s<k) { cout<<"NO"<<endl; return ;}
  19. cout<<"YES"<<endl;
  20. int t=;
  21. while(s)
  22. {
  23. if(s-n+>=k-)
  24. {
  25. if(t%==) cout<<n<<" ";
  26. else cout<<<<" ";
  27. t++;
  28. k--;
  29. s=s-(n-); //cout<<s<<endl;
  30. }
  31. else
  32. {
  33. int d=s-(k-);// cout<<d<<endl;
  34. int pos=;
  35. if(t%==) { cout<<+d<<" "; pos=+d; }
  36. else { cout<<n-d<<" "; pos=n-d;}
  37. t++;
  38. k--;
  39. int x=;
  40. while(k)
  41. {
  42. if(x%==)
  43. {
  44. if(pos->=) cout<<pos-<<" ";
  45. else cout<<pos+<<" ";
  46. }
  47. else cout<<pos<<" ";
  48. k--;
  49. x++;
  50. }
  51. break;
  52. }
  53. }
  54. }

D.cpp

E1. Stars Drawing (Easy Edition)

可以直接暴力搜  找到一个点  直接往上下左右搜  看照射的距离  大于1就全部标记

  1. #include<bits/stdc++.h>
  2. #define int long long
  3. #define MAX(a,b,c) max(a,max(b,c))
  4. #define MIN(a,b,c) min(a,min(b,c))
  5. #define pb push_back
  6. #define fi first
  7. #define se second
  8. typedef long long ll;
  9. typedef long long LL;
  10. typedef unsigned long long ull;
  11. typedef unsigned long long uLL;
  12. using namespace std;
  13. pair<int,int> pos[]={ {,},{,-},{,},{-,} };
  14. bool tf[][];
  15. char a[][];
  16. int x2[];
  17. int x1[];
  18. int x3[];
  19. int32_t main()
  20. {
  21. int n,m; cin>>n>>m; getchar();
  22. for(int i=;i<n;i++)
  23. gets(a[i]);
  24. int t=;
  25. for(int i=;i<n;i++)
  26. {
  27. for(int j=;j<m;j++)
  28. {
  29. if(a[i][j]=='*')
  30. {
  31. //cout<<i<<" "<<j<<endl;
  32. int z=;
  33. while()
  34. {
  35. int x=;
  36. for(int k=;k<;k++)
  37. {
  38. int x1=i+z*pos[k].first;
  39. int y1=j+z*pos[k].second;
  40. if(x1<||x1>=n||y1<||y1>=m)
  41. {
  42. continue;
  43. }
  44. if(a[x1][y1]=='*')
  45. {
  46. x++;
  47. }
  48.  
  49. }
  50. //cout<<x<<endl;
  51. if(x==)
  52. {
  53. tf[i][j]=;
  54. for(int k=;k<;k++)
  55. {
  56. int x1=i+z*pos[k].first;
  57. int y1=j+z*pos[k].second;
  58. if(x1<||x1>=n||y1<||y1>=m)
  59. {
  60. continue;
  61. }
  62. if(a[x1][y1]=='*')
  63. {
  64. tf[x1][y1]=;
  65. }
  66.  
  67. }
  68. }
  69. else break;
  70. z++;
  71. }
  72. if(z==) continue;
  73. else
  74. {
  75. x1[t]=i;
  76. x2[t]=j;
  77. x3[t]=z-; t++;
  78. }
  79. }
  80. }
  81. } // cout<<t<<endl;
  82. int k1=;
  83. int k2=;
  84. for(int i=;i<n;i++)
  85. {
  86. for(int j=;j<m;j++)
  87. {
  88. if(a[i][j]=='*') k1++;
  89. if(tf[i][j]==) k2++;
  90. }
  91. }
  92. if(k1!=k2) cout<<-<<endl;
  93. else
  94. {
  95. cout<<t<<endl;
  96. for(int i=;i<t;i++)
  97. {
  98. cout<<x1[i]+<<" "<<x2[i]+<<" "<<x3[i]<<endl;
  99. }
  100. } //cout<<k1<<" "<<k2<<endl;
  101. }

E1.cpp

E2. Stars Drawing (Hard Edition)

先预处理 每个点 上下左右 可以照射的距离   再标记

预处理有些技巧 ,不能暴力搜  要找相邻两个点的关系

由于预处理 和 标记 分开  不会超时;

  1. #include<bits/stdc++.h>
  2. using namespace std;
  3. const int maxn=1e3+;
  4. int l[maxn][maxn];
  5. int r[maxn][maxn];
  6. int u[maxn][maxn];
  7. int d[maxn][maxn];
  8. int ans1[maxn*maxn];
  9. int ans2[maxn*maxn];
  10. int ans3[maxn*maxn];
  11. char a[maxn][maxn];
  12. bool f[maxn][maxn];
  13. int main()
  14. {
  15. int n,m;
  16. cin >> n >> m;
  17. int i,j,s,y;
  18. for (i = ; i <= n; i++)
  19. for (j = ; j <= m; j++) cin >> a[i][j];
  20. for (i = ; i <= n; i++) for (j = ; j <= m; j++)
  21. if (a[i][j] == '*') l[i][j] = l[i][j-] + ; else l[i][j] = ;
  22.  
  23. for (i = ; i <= n; i++) for (j = m; j >= ; j--)
  24. if (a[i][j] == '*') r[i][j] = r[i][j+] + ; else r[i][j] = ;
  25.  
  26. for (j = ; j <= m; j++) for (i = ; i <= n; i++)
  27. if (a[i][j] == '*') u[i][j] = u[i-][j] + ; else u[i][j] = ;
  28.  
  29. for (j = m; j >= ; j--) for (i = n; i >= ; i--)
  30. if (a[i][j] == '*') d[i][j] = d[i+][j] + ; else d[i][j] = ;
  31.  
  32. int t=;
  33. for (i = ; i <= n; i++)
  34. for (j = ; j <= m; j++) if (a[i][j] == '*') {
  35. s = min(min(r[i][j+],l[i][j-]),min(u[i-][j],d[i+][j]));
  36. if (s > ) {
  37. ans1[t]=i; ans2[t]=j; ans3[t]=s; t++;
  38.  
  39. for (y = j-s; y <= j+s; y++) f[i][y] = ;
  40. for (y = i-s; y <= i+s; y++) f[y][j] = ;
  41. }
  42. }
  43. for (i = ; i <= n; i++) for (j = ; j <= m; j++)
  44. if (a[i][j] == '*' && f[i][j] == ) {
  45. cout << - << endl;
  46. return ;
  47. }
  48. cout<<t-<<endl;
  49. for(int i=;i<=t-;i++)
  50. cout<<ans1[i]<<" "<<ans2[i]<<" "<<ans3[i]<<endl;
  51. }

E2.cpp

Codeforces Div3 #501 A-E(2) F以后补的更多相关文章

  1. Codeforces Round #501 (Div. 3) F. Bracket Substring

    题目链接 Codeforces Round #501 (Div. 3) F. Bracket Substring 题解 官方题解 http://codeforces.com/blog/entry/60 ...

  2. Codeforces Round #598 (Div. 3) A,B,C,D{E,F待补}

    A. Payment Without Change   #include<bits/stdc++.h> using namespace std; #define int long long ...

  3. Codeforces Round #535 (Div. 3) [codeforces div3 难度测评]

    hhhh感觉我真的太久没有接触过OI了 大约是前天听到JK他们约着一起刷codeforces,假期里觉得有些颓废的我忽然也心血来潮来看看题目 今天看codeforces才知道居然有div3了,感觉应该 ...

  4. Codeforces Round #541 (Div. 2) (A~F)

    目录 Codeforces 1131 A.Sea Battle B.Draw! C.Birthday D.Gourmet choice(拓扑排序) E.String Multiplication(思路 ...

  5. Codeforces Round #519 by Botan Investments F. Make It One

    https://codeforces.com/contest/1043/problem/F 题意 给你n个数,求一个最小集合,这个集合里面数的最大公因数等于1 1<=n<=3e5 1< ...

  6. Codeforces Round #532 (Div. 2):F. Ivan and Burgers(贪心+异或基)

    F. Ivan and Burgers 题目链接:https://codeforces.com/contest/1100/problem/F 题意: 给出n个数,然后有多个询问,每次回答询问所给出的区 ...

  7. Codeforces Round #590 (Div. 3)(e、f待补

    https://codeforces.com/contest/1234/problem/A A. Equalize Prices Again #include<bits/stdc++.h> ...

  8. Codeforces Round #600 (Div. 2)E F

    题:https://codeforces.com/contest/1253/problem/E 题意:给定n个信号源,俩个参数x和s,x代表这个信号源的位置,s代表这个信号源的波及长度,即这个信号源可 ...

  9. Codeforces Round #346 (Div. 2) E F

    因为很久没有个人认真做题了 昨天晚上开了场虚拟cf来锻炼个人手速 选的是第一次做cf的场 那时候7出3还被hack...之后也没补题 这次做的时候顺便回忆了一下以前比赛的时候是怎么想的 发现经验还是很 ...

随机推荐

  1. 阿里云免费申请https证书

    申请地址   https://common-buy.aliyun.com/?spm=a2c4e.11153940.blogcont65199.22.30f968210RsUSx&commodi ...

  2. QuickStart系列:docker部署之MariaDB

    Centos7里面没有Mysql 取而代之的是MariaDB,MariaDB是完全开源的.MariaDB数据库管理系统是MySQL的一个分支,主要由开源社区在维护,采用GPL授权许可 MariaDB的 ...

  3. Ubuntu 16.04 中安装谷歌 Chrome 浏览器

    http://jingyan.baidu.com/article/335530da98061b19cb41c31d.html 根据教程安装成功!! http://askubuntu.com/quest ...

  4. unity中鼠标按下加速漫游,鼠标抬起减速漫游。

    private bool IsMouseUpOrDown=true; //一开始默认是鼠标抬起状态 if (Input.GetMouseButtonDown(1)) //鼠标按下的瞬间状态 { IsM ...

  5. vue安装与配置

    直接引入 <script src="https://unpkg.com/vue"></script> 用npm安装   $ npm install vue ...

  6. Python自学笔记-装饰器1(廖雪峰的网站)

    由于函数也是一个对象,而且函数对象可以被赋值给变量,所以,通过变量也能调用该函数. >>> def now(): ... print('2015-3-25') ... >> ...

  7. Unicode与中文转换工具类方法(转)

    /* * 中文转unicode编码 */ public static String gbEncoding(final String gbString) { char[] utfBytes = gbSt ...

  8. WinPcap是用于网络封包抓取的一套工具

    WinPcap是用于网络封包抓取的一套工具,可适用于32位的操作平台上解析网络封包,包含了核心的封包过滤,一个底层动态链接库,和一个高层系统函数库,及可用来直接存取封包的应用程序界面. Winpcap ...

  9. Python爬虫框架Scrapy实例(三)数据存储到MongoDB

    Python爬虫框架Scrapy实例(三)数据存储到MongoDB任务目标:爬取豆瓣电影top250,将数据存储到MongoDB中. items.py文件复制代码# -*- coding: utf-8 ...

  10. JAVA自动补全代码

    打开eclipse(对myeclipse同样适用) 找到窗口(windows)菜单,打开最后一项首选项(Preferences)找到下属菜单java打开,打开里边的编辑器(Editor)菜单,点击内容 ...