A,水题不多说。

  1. #include<bits/stdc++.h>
  2. using namespace std;
  3.  
  4. //#define LOCAL
  5. int main()
  6. {
  7. #ifdef LOCAL
  8. freopen("in.txt","r",stdin);
  9. #endif
  10. int n,t; scanf("%d%d",&n,&t);
  11. if(t<){
  12. for(int i = n; i--;) putchar(''+t);
  13. }else{
  14. if(n == ) puts("-1");
  15. else{
  16. putchar('');
  17. for(int i = n; --i;) putchar('');
  18. }
  19. }
  20. return ;
  21. }

A

B,用补集算一下。

  1. #include<bits/stdc++.h>
  2. using namespace std;
  3.  
  4. const int mod = 1e9+;
  5. typedef long long ll;
  6. int qpow(int a,int q)
  7. {
  8. int re = ;
  9. while(q){
  10. if(q&) re = (ll)re*a%mod;
  11. a = (ll)a*a%mod;
  12. q >>= ;
  13. }
  14. return re;
  15. }
  16.  
  17. //#define LOCAL
  18. int main()
  19. {
  20. #ifdef LOCAL
  21. freopen("in.txt","r",stdin);
  22. #endif
  23. int n; scanf("%d",&n);
  24. int ans = (qpow(,n)-qpow(,n)+mod)%mod;
  25. printf("%d",ans);
  26. return ;
  27. }

B

C,当s1[i] != s2[i]的时候至少其中f值+1,效果记为10,01,11(与s1[i]和s2[i]都不同)

s1[i] == s2[i]的时候效果记为11 00。

记s[i] != s[i]有ct1个,为了保证两个f相等如果ct是奇数,单出来那个只有使得f1,f2同时加1,所以下界为low = (ct+1)/2。

其中有ct/2个对10,01 。当t<low的时候无解。

记s1[i]==s2[i]有ct2 = n-ct1个,当t>=low && t <= low+ct2的时候,只要在s1[i]==s2[i]时取相应个数个的ch,ch !=s1[i]。(11)

当t>=low+ct2的时候,需要从ct/2对中选出一些来变成 11,11

  1. #include<bits/stdc++.h>
  2. using namespace std;
  3.  
  4. const int LEN = 1e5+;
  5. char s[][LEN];
  6.  
  7. //#define LOCAL
  8. int main()
  9. {
  10. #ifdef LOCAL
  11. freopen("in.txt","r",stdin);
  12. #endif
  13. int n,t; scanf("%d%d\n",&n,&t);
  14. gets(s[]); gets(s[]);
  15. int ct1 = ;
  16. for(int i = ; i < n; i++){
  17. ct1 += s[][i] == s[][i];
  18. }
  19. int ct2 = n-ct1;
  20. int low = (ct2+)/;
  21. if(t < low){
  22. puts("-1");
  23. }else {
  24. int pir = low - (ct2&);
  25. int del = t - low - ct1;
  26. int swc = , ct, ex;
  27. if(del > ) {
  28. ex = ct1;
  29. ct = (pir - del)*;
  30. }else {
  31. ct = (pir)*;
  32. ex = t - low;
  33. }
  34. for(int i = ; i < n; i++){
  35. if(s[][i] != s[][i]){
  36. if(ct){ //控制 01
  37. ct--;
  38. putchar(s[swc ^= ][i]);
  39. }else {
  40. for(char c = 'a'; c <= 'z'; c++){
  41. if(c != s[][i] && c != s[][i]) {
  42. putchar(c); break;
  43. }
  44. }
  45. }
  46. }else {
  47. if(ex){ //控制11
  48. ex--;
  49. for(char c = 'a'; c <= 'z'; c++){
  50. if(c != s[][i] && c != s[][i]) {
  51. putchar(c); break;
  52. }
  53. }
  54. }else {
  55. putchar(s[][i]);
  56. }
  57. }
  58. }
  59. }
  60. return ;
  61. }

C

D,暴力,有个事实是1e9以内的的素数间隔不超过282,sqrt(N)判断一下就好了。

  1. #include<bits/stdc++.h>
  2. using namespace std;
  3.  
  4. const int maxn = 1e5+;
  5. int Prim[maxn], sz ;
  6. bool vis[maxn];
  7. void seive(int n = maxn-)
  8. {
  9. int m = (int)sqrt(n+0.5);
  10. for(int i = ; i <= m; i++){
  11. if(!vis[i])
  12. for(int j = i*i; j <= n; j += i){
  13. vis[j] = true;
  14. }
  15. }
  16. for(int i = ; i <= n; i++){
  17. if(!vis[i]) Prim[sz++] = i;
  18. }
  19. }
  20.  
  21. bool chkPrime(int x)
  22. {
  23. int m = (int)sqrt(x+0.5);
  24. for(int i = ; Prim[i] <= m; i++){
  25. if(x%Prim[i] == ) return false;
  26. }
  27. return true;
  28. }
  29.  
  30. //#define LOCAL
  31. int main()
  32. {
  33. #ifdef LOCAL
  34. freopen("in.txt","r",stdin);
  35. #endif
  36. seive();
  37. int n; scanf("%d",&n);
  38. if(chkPrime(n)){
  39. puts("");
  40. printf("%d",n);
  41. }else if(chkPrime(n-)){
  42. puts("");
  43. printf("%d %d",,n-);
  44. }else {
  45. puts("");
  46. for(int i = ; ; i += ){
  47. if(chkPrime(n-i)){
  48. printf("%d ",n-i);
  49. n = i;
  50. break;
  51. }
  52. }
  53. for(int i = ; Prim[i] <= n; i++){
  54. if(chkPrime(n-Prim[i])){
  55. printf("%d %d",Prim[i],n-Prim[i]);
  56. break;
  57. }
  58. }
  59. }
  60. return ;
  61. }

D

E,问交换的最小花费。看成一个置换环,最优的交换就是不断消去端点,但是这样不太好写。

一般两个排列问相对关系都可以把其中一个做映射会方便处理。把序列b映射成1...n,把a按照相同规则映射,并记录映射后元素x的位置。

从小的元素枚举,找到它在序列中的位置p[x],小的要往左边走,判断一下左边的元素是不是要往大于p[x]的位置走。如果是就交换。

p[x]的位置前面一定会有一个不小于p[x]的元素。

  1. #include<bits/stdc++.h>
  2. using namespace std;
  3.  
  4. const int maxn = ;
  5. int mp[maxn];
  6. int a[maxn],p[maxn];
  7.  
  8. #define PB push_back
  9. #define MP make_pair
  10. #define fi first
  11. #define se second
  12.  
  13. //#define LOCAL
  14. int main()
  15. {
  16. #ifdef LOCAL
  17. freopen("in.txt","r",stdin);
  18. #endif
  19. int n; scanf("%d",&n);
  20. for(int i = ; i <= n; i++){
  21. scanf("%d",a+i);
  22. }
  23. for(int i = ; i <= n; i++){
  24. int x; scanf("%d",&x);
  25. mp[x] = i;
  26. }
  27. for(int i = ; i <= n; i++){
  28. p[ a[i] = mp[a[i]] ] = i;
  29. }
  30.  
  31. int c = ;
  32. for(int x = ; x <= n; x++){
  33. for(int j = p[x]; --j>=x ; ){
  34. if(a[j] >= p[x]){
  35. c += p[x] - j;
  36. swap(a[j],a[p[x]]);
  37. ans.PB(MP(j,p[x]));
  38. p[a[j]] = p[x];
  39. p[x] = j;
  40. }
  41. }
  42. }
  43.  
  44. printf("%d\n",c);
  45. printf("%d\n",(int)ans.size());
  46. for(auto i: ans){
  47. printf("%d %d\n",i.fi,i.se);
  48. }
  49. return ;
  50. }

E

Codeforces Round #324 (Div. 2) A B C D E的更多相关文章

  1. Codeforces Round #324 (Div. 2)解题报告

    ---恢复内容开始--- Codeforces Round #324 (Div. 2) Problem A 题目大意:给二个数n.t,求一个n位数能够被t整除,存在多组解时输出任意一组,不存在时输出“ ...

  2. Codeforces Round #324 (Div. 2) C (二分)

    题目链接:http://codeforces.com/contest/734/problem/C 题意: 玩一个游戏,一开始升一级需要t秒时间,现在有a, b两种魔法,两种魔法分别有m1, m2种效果 ...

  3. Codeforces Round #324 (Div. 2) E. Anton and Ira 贪心

    E. Anton and Ira Time Limit: 1 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/584/probl ...

  4. Codeforces Round #324 (Div. 2) D. Dima and Lisa 哥德巴赫猜想

    D. Dima and Lisa Time Limit: 1 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/584/probl ...

  5. Codeforces Round #324 (Div. 2) C. Marina and Vasya 贪心

    C. Marina and Vasya Time Limit: 1 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/584/pr ...

  6. Codeforces Round #324 (Div. 2) B. Kolya and Tanya 快速幂

    B. Kolya and Tanya Time Limit: 1 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/584/pro ...

  7. Codeforces Round #324 (Div. 2) A. Olesya and Rodion 水题

    A. Olesya and Rodion Time Limit: 1 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/584/p ...

  8. Codeforces Round #324 (Div. 2) (哥德巴赫猜想)

    题目:http://codeforces.com/problemset/problem/584/D 思路: 关于偶数的哥德巴赫猜想:任一大于2的偶数都可写成两个素数之和. 关于奇数的哥德巴赫猜想:任一 ...

  9. Codeforces Round #324 (Div. 2) Dima and Lisa 哥德巴赫猜想

    原题链接:http://codeforces.com/contest/584/problem/D 题意: 给你一个奇数,让你寻找三个以内素数,使得和为这个奇数. 题解: 这题嘛...瞎比搞搞就好,首先 ...

  10. Codeforces Round #324 (Div. 2) Marina and Vasya 乱搞推理

    原题链接:http://codeforces.com/contest/584/problem/C 题意: 定义$f(s1,s2)$为$s1,s2$不同的字母的个数.现在让你构造一个串$s3$,使得$f ...

随机推荐

  1. Scrapy框架初探

    Scrapy 貌似是 Python 最出名的爬虫框架 0. 文档 中文文档:https://scrapy-chs.readthedocs.io/zh_CN/0.24/intro/tutorial.ht ...

  2. Spark内核概述

    提交Spark程序的机器一般一定和Spark集群在同样的网络环境中(Driver频繁和Executors通信),且其配置和普通的Worker一致 1. Driver: 具有main方法的,初始化 Sp ...

  3. 洛谷P3052 [USACO12MAR]摩天大楼里的奶牛Cows in a Skyscraper

    P3052 [USACO12MAR]摩天大楼里的奶牛Cows in a Skyscraper 题目描述 A little known fact about Bessie and friends is ...

  4. day04 ---Linux安装Python3

    如何linux上安装python3 1.下载源代码,方式有2个, 1.在windows上下载,下载完成后,通过lrzsz工具,或者xftp工具,传输到linux服务器中 2.在linux中直接下载 c ...

  5. CSS之flex兼容

    我觉得写的很好的文章,但是我又没有时间去整理的. https://blog.csdn.net/u010130282/article/details/52627661 百分比 是在宽度自适应的时候要用 ...

  6. 项目 07 Model与数据优化

    项目班 07 Model与数据优化 html默认可以用直接用的方法和变量 {{ static_url(p.image_url) }} #static_url表示直接获取静态文件url {{ handl ...

  7. JS——数组、==和===的区别

    创建数组的方式: 1) <script type='text/javascript'> var aRr = new Array(1,2,3,4,'abc',3) </script&g ...

  8. python3 no module named PIL

    sudo apt-get install python3-imaging

  9. ubuntu操作技巧

    1打开终端:ctrl+alt 2退出crtl+d

  10. D. Beautiful numbers

    题目链接:http://codeforces.com/problemset/problem/55/D D. Beautiful numbers time limit per test 4 second ...