https://zoj.pintia.cn/contests/91827364639/problems

C

要把这两个二进制串变为相同,需要先看哪些位置不同,设为数组c,某位为1则两位不同。

分1形成两段、四段或者更多段来考虑。

  1. #include <iostream>
  2. #include <cstdio>
  3. #include <string>
  4. #include <cstring>
  5. #include <algorithm>
  6. #include <cmath>
  7. #include <stack>
  8. #include <vector>
  9. #include <set>
  10. #include <cmath>
  11. #include <queue>
  12. #include <map>
  13. #define ll long long
  14. #define ld double
  15. #define lson rt << 1, l, m
  16. #define pi acos(-1)
  17. #define rson rt << 1 | 1, m + 1, r
  18. #define fo(i, l, r) for (long long i = l; i <= r; i++)
  19. #define fd(i, l, r) for (long long i = r; i >= l; i--)
  20. #define mem(x) memset(x, 0, sizeof(x))
  21. #define eps 1e-10
  22. using namespace std;
  23. const ll maxn = ;
  24. const ll mod = ;
  25. ll read()
  26. {
  27. ll x = , f = ;
  28. char ch = getchar();
  29. while (!(ch >= '' && ch <= ''))
  30. {
  31. if (ch == '-')
  32. f = -;
  33. ch = getchar();
  34. };
  35. while (ch >= '' && ch <= '')
  36. {
  37. x = x * + (ch - '');
  38. ch = getchar();
  39. };
  40. return x * f;
  41. }
  42. int n,m;
  43. char s[maxn],t[maxn];
  44. int pt[];
  45. ll ans;
  46. int main()
  47. {
  48.  
  49. int T;
  50. T = read();
  51. int tt = ;
  52. while (T--)
  53. {
  54. ans=;
  55. n=read();
  56. scanf("%s",s+);
  57. scanf("%s",t+);
  58. fo(i,,n){
  59. s[i]-='';
  60. t[i]-='';
  61. s[i] ^= t[i];
  62. }
  63. int cnt = ;
  64. fo(i,,n){
  65. if(s[i]&&!s[i-]){
  66. pt[++cnt]=i;
  67. }
  68. if(s[i]&&!s[i+]){
  69. pt[++cnt]=i;
  70. }
  71. if(cnt>)break;
  72. }
  73. if(cnt>){
  74. printf("0\n");
  75. continue;
  76. }
  77. if(cnt==){
  78. ans=(ll)n*(n+)/;
  79. }
  80. if(cnt==){
  81. ans=n+n-;
  82. }
  83. if(cnt==){
  84. ans=;
  85. }
  86. printf("%d\n",ans);
  87.  
  88. }
  89.  
  90. return ;
  91. }

M

递归,碰到循环节就停止。

  1. #include <iostream>
  2. #include <cstdio>
  3. #include <string>
  4. #include <cstring>
  5. #include <algorithm>
  6. #include <cmath>
  7. #include <stack>
  8. #include <vector>
  9. #include <set>
  10. #include <cmath>
  11. #include <queue>
  12. #include <map>
  13. #define ll long long
  14. #define ld double
  15. #define lson rt << 1, l, m
  16. #define pi acos(-1)
  17. #define rson rt << 1 | 1, m + 1, r
  18. #define fo(i, l, r) for (long long i = l; i <= r; i++)
  19. #define fd(i, l, r) for (long long i = r; i >= l; i--)
  20. #define mem(x) memset(x, 0, sizeof(x))
  21. #define eps 1e-10
  22. using namespace std;
  23. const ll maxn = ;
  24. const ll mod = ;
  25. ll read()
  26. {
  27. ll x = , f = ;
  28. char ch = getchar();
  29. while (!(ch >= '' && ch <= ''))
  30. {
  31. if (ch == '-')
  32. f = -;
  33. ch = getchar();
  34. };
  35. while (ch >= '' && ch <= '')
  36. {
  37. x = x * + (ch - '');
  38. ch = getchar();
  39. };
  40. return x * f;
  41. }
  42. ll x,k;
  43. ll f[] = {,,,,,,,,,};
  44. ll g(int d,ll x){
  45. if(d==) return x;
  46. if(x==||x==){
  47. return x^(d&);
  48. }
  49. ll ret = ;
  50. while(x){
  51. ret += f[x%];
  52. x /= ;
  53. }
  54. return g(d-,ret);
  55. }
  56. int main()
  57. {
  58.  
  59. int T;
  60. T = read();
  61. int tt = ;
  62. while (T--)
  63. {
  64. x=read();k=read();
  65. printf("%lld\n",g(k,x));
  66. }
  67. return ;
  68. }

J

正好买m本书,还要带的钱最多。

考虑到,如果跳过若干本书,买一本,那把后一本书换成一开始跳过的书,答案会增加。

即,不存在这样的情况,买的书肯定是从1开始到m。

这个时候答案依然可能增加,要保证之后买不了书,就是加上之后价格最小的那本书-1

再判断一些特殊情况就可以。

  1. #include <iostream>
  2. #include <cstdio>
  3. #include <string>
  4. #include <cstring>
  5. #include <algorithm>
  6. #include <cmath>
  7. #include <stack>
  8. #include <vector>
  9. #include <set>
  10. #include <cmath>
  11. #include <queue>
  12. #include <map>
  13. #define ll long long
  14. #define ld double
  15. #define lson rt << 1, l, m
  16. #define pi acos(-1)
  17. #define rson rt << 1 | 1, m + 1, r
  18. #define fo(i, l, r) for (long long i = l; i <= r; i++)
  19. #define fd(i, l, r) for (long long i = r; i >= l; i--)
  20. #define mem(x) memset(x, 0, sizeof(x))
  21. #define eps 1e-10
  22. using namespace std;
  23. const ll maxn = ;
  24. const ll mod = ;
  25. ll read()
  26. {
  27. ll x = , f = ;
  28. char ch = getchar();
  29. while (!(ch >= '' && ch <= ''))
  30. {
  31. if (ch == '-')
  32. f = -;
  33. ch = getchar();
  34. };
  35. while (ch >= '' && ch <= '')
  36. {
  37. x = x * + (ch - '');
  38. ch = getchar();
  39. };
  40. return x * f;
  41. }
  42. int n,m;
  43. ll a[maxn],ans;
  44. int main()
  45. {
  46.  
  47. int T;
  48. T = read();
  49. int tt = ;
  50. while (T--)
  51. {
  52. ans=;
  53. n=read();m=read();
  54. fo(i,,n){
  55. a[i]=read();
  56. if(!a[i]){
  57. i--;
  58. n--;
  59. m--;
  60. }
  61. }
  62. if(m<||m>n){
  63. printf("Impossible\n");
  64. continue;
  65. }
  66. if(m==n){
  67. printf("Richman\n");
  68. continue;
  69. }
  70. fo(i,,m){
  71. ans += a[i];
  72. }
  73. ll mn = 1e10;
  74. fo(i,m+,n){
  75. mn = min(mn,a[i]);
  76. }
  77. mn--;
  78. ans+=mn;
  79. printf("%lld\n",ans);
  80. }
  81.  
  82. return ;
  83. }

E

试着将操作进行分解,前进n次,倒退n次,把这些操作全部换成前进1次,倒退1次的操作,答案不会变劣。

首先二分,检验的时候,不断往前走,如果某个时刻发现前一个点不能满足要求,就在这两个点之间反复的跳,注意考虑最后一个点的情况。

  1. #include <iostream>
  2. #include <cstdio>
  3. #include <string>
  4. #include <cstring>
  5. #include <algorithm>
  6. #include <cmath>
  7. #include <stack>
  8. #include <vector>
  9. #include <set>
  10. #include <cmath>
  11. #include <queue>
  12. #include <map>
  13. #define ll long long
  14. #define ld double
  15. #define lson rt << 1, l, m
  16. #define pi acos(-1)
  17. #define rson rt << 1 | 1, m + 1, r
  18. #define fo(i, l, r) for (long long i = l; i <= r; i++)
  19. #define fd(i, l, r) for (long long i = r; i >= l; i--)
  20. #define mem(x) memset(x, 0, sizeof(x))
  21. #define eps 1e-10
  22. using namespace std;
  23. const ll maxn = ;
  24. const ll mod = ;
  25. ll read()
  26. {
  27. ll x = , f = ;
  28. char ch = getchar();
  29. while (!(ch >= '' && ch <= ''))
  30. {
  31. if (ch == '-')
  32. f = -;
  33. ch = getchar();
  34. };
  35. while (ch >= '' && ch <= '')
  36. {
  37. x = x * + (ch - '');
  38. ch = getchar();
  39. };
  40. return x * f;
  41. }
  42. ll a[maxn],b[maxn],c[maxn];
  43. ll n,m,mx;
  44. bool check(ll t){
  45. int nown = n;
  46. fo(i,,n){
  47. b[i]=t/a[i];
  48. if(b[i]*a[i]<t)b[i]++;
  49. }
  50. b[n+]=;
  51. while(nown>=&&b[nown]==)nown--;
  52. fo(i,,nown+){
  53. if(i<=n)c[i]=;
  54. else c[i]=;
  55. if(b[i-]>c[i-]){
  56. c[i] += b[i-]-c[i-];
  57. c[i-]=b[i-];
  58. }
  59. if(i==n&&c[i]>b[i])c[i]--;
  60.  
  61. }
  62. ll ret = ;
  63. fo(i,,nown+){
  64. ret += c[i];
  65. if(ret > m) return false;
  66. }
  67. return true;
  68. }
  69. int main()
  70. {
  71.  
  72. int T;
  73. T = read();
  74. int tt = ;
  75. while (T--)
  76. {
  77. n=read();m=read();
  78. mx=;
  79. fo(i,,n){
  80. a[i]=read();
  81. mx=max(mx,a[i]);
  82. }
  83. ll lp = ,rp = mx*m,mid,ans=;
  84. while(lp<=rp){
  85. mid = (lp + rp) >> ;
  86. if(check(mid)){
  87. ans = mid;
  88. lp = mid + ;
  89. }else{
  90. rp = mid - ;
  91. }
  92. }
  93. printf("%lld\n",ans);
  94. }
  95.  
  96. return ;
  97. }

F

首先,n个人最多打n-1轮,奇数个人不能打。

2、4个人都能打,然后发现6个人连两轮都打不了。

一开始是 2 1 4 3 6 5,假如说之后1个3打,按照只能要求1 2 3 4之间有比赛,5还是只能跟6打,因为第二轮与人的序号无关,这时候怎么调整都是徒劳。

人数是2^n的时候比较好安排,轮换一下就可以。

人数不是2^n的时候,还是按照2^n的情况排个表,因为之前就是保证字典序最小,所以编号大的都尽量出现在后面,如果这个时候表中出现了不得不跟一个不存在的大号打的情况,这个时候就安排不了了。

  1. #include<iostream>
  2. #include<cstdio>
  3. #include<string>
  4. #include<cstring>
  5. #include<algorithm>
  6. #include<cmath>
  7. #include<vector>
  8. #include <set>
  9. #include <queue>
  10. #define ll long long
  11. #define ld long double
  12. #define lson l,m,rt<<1
  13. #define pi acos(-1)
  14. #define rson m+1,r,rt<<1|1
  15. #define fo(i,l,r) for(int i = l;i <= r;i++)
  16. #define fd(i,l,r) for(int i = r;i >= l;i--)
  17. #define mem(x) memset(x,0,sizeof(x))
  18. #define eps 3e-11
  19. using namespace std;
  20. const int maxn = ;
  21. const ll inf = 1e9;
  22. const ll mod = ;
  23. ll read() {
  24. ll x=,f=;
  25. char ch=getchar();
  26. while(!(ch>=''&&ch<='')) {
  27. if(ch=='-')f=-;
  28. ch=getchar();
  29. };
  30. while(ch>=''&&ch<='') {
  31. x=x*+(ch-'');
  32. ch=getchar();
  33. };
  34. return x*f;
  35. }
  36. int n,k;
  37. int a[][];
  38. int main() {
  39. a[][]=a[][]=;
  40. a[][]=a[][]=;
  41. for(int t = ;t <= ;t <<= ){
  42. fo(i,,t){
  43. fo(j,,t){
  44. a[t+i][t+j] = a[i][j];
  45. a[t+i][j] = a[i][t+j] = a[i][j] + t;
  46. }
  47. }
  48. }
  49. int T=read();
  50. while(T--){
  51. n=read();k=read();
  52. if((n&)||k>=n){
  53. puts("Impossible");
  54. continue;
  55. }
  56. bool flag = false;
  57. fo(i,,k){
  58. fo(j,,n){
  59. if(a[i+][j] > n)flag=true;
  60. }
  61. }
  62. if(flag){
  63. puts("Impossible");
  64. continue;
  65. }
  66. fo(i,,k){
  67. fo(j,,n){
  68. printf("%d",a[i+][j]);
  69. putchar(j==n?'\n':' ');
  70. }
  71. }
  72. }
  73. return ;
  74. }

D

枚举两个数的第一位,之后所有的位都确定了。

注意两位数不能有前导零,每一位的范围不能超。

  1. #include<iostream>
  2. #include<cstdio>
  3. #include<string>
  4. #include<cstring>
  5. #include<algorithm>
  6. #include<cmath>
  7. #include<vector>
  8. #include <set>
  9. #include <queue>
  10. #define ll long long
  11. #define ld long double
  12. #define lson l,m,rt<<1
  13. #define pi acos(-1)
  14. #define rson m+1,r,rt<<1|1
  15. #define fo(i,l,r) for(int i = l;i <= r;i++)
  16. #define fd(i,l,r) for(int i = r;i >= l;i--)
  17. #define mem(x) memset(x,0,sizeof(x))
  18. #define eps 3e-11
  19. using namespace std;
  20. const int maxn = ;
  21. const ll inf = 1e9;
  22. const ll mod = ;
  23. ll read() {
  24. ll x=,f=;
  25. char ch=getchar();
  26. while(!(ch>=''&&ch<='')) {
  27. if(ch=='-')f=-;
  28. ch=getchar();
  29. };
  30. while(ch>=''&&ch<='') {
  31. x=x*+(ch-'');
  32. ch=getchar();
  33. };
  34. return x*f;
  35. }
  36. ll n,m,len;
  37. char s[maxn];
  38. int a[maxn],b[maxn];
  39. bool flag;
  40. inline int check(int u,int v,int t){
  41. if(a[u]*b[v]==s[t])return ;
  42. if(t<len&&s[t]&&(s[t]*+s[t+])==a[u]*b[v]) return ;
  43. return ;
  44. }
  45. inline int dv(int v,int t){
  46. if(s[t]%v==) return s[t]/v;
  47. if(t<len&&(s[t]*+s[t+])%v==) return (s[t]*+s[t+])/v;
  48. return -;
  49. }
  50. bool check(int st){
  51. int t = st,u=,v=,sgn;
  52. while(t<=len){
  53. v++;
  54. if(v>m){
  55. v=;
  56. u++;
  57. }
  58. if(u>n)break;
  59. if(u==){
  60. b[v]=dv(a[u],t);
  61. if(b[v]==-||b[v]>=)return false;
  62. }else if(v==){
  63. a[u] = dv(b[v],t);
  64. if(a[u]==-||a[u]>=)return false;
  65. }else{
  66. sgn=check(u,v,t);
  67. if(!sgn)return false;
  68. }
  69. t++;
  70. if(a[u]*b[v]>=)t++;
  71. }
  72. return u==n&&v==m&&t==len+;
  73. }
  74. bool gao(){
  75. int sgn;
  76. fo(i,,){
  77. fo(j,,){
  78. a[]=i;b[]=j;
  79. sgn=check(,,);
  80. if(!sgn)continue;
  81. if(check(sgn+))return true;
  82. }
  83. }
  84. return false;
  85. }
  86. int main() {
  87. int T=read();
  88. while(T--){
  89. flag=false;
  90. n=read();m=read();
  91. scanf("%s",s+);
  92. len = strlen(s+);
  93. if(n*m>len||n*m*<len){
  94. puts("Impossible");
  95. continue;
  96. }
  97. fo(i,,len) s[i]-='';
  98. if(gao()){
  99. fo(i,,n){
  100. putchar(''+a[i]);
  101. }
  102. putchar(' ');
  103. fo(i,,m){
  104. putchar(''+b[i]);
  105. }
  106. putchar('\n');
  107. }else{
  108. puts("Impossible");
  109. }
  110. }
  111. return ;
  112. }

2018 icpc 青岛的更多相关文章

  1. 2018 icpc 青岛网络赛 J.Press the Button

    Press the Button Time Limit: 1 Second      Memory Limit: 131072 KB BaoBao and DreamGrid are playing ...

  2. 2018 ICPC青岛网络赛 B. Red Black Tree(倍增lca好题)

    BaoBao has just found a rooted tree with n vertices and (n-1) weighted edges in his backyard. Among ...

  3. 2018 ICPC 沈阳网络赛

    2018 ICPC 沈阳网络赛 Call of Accepted 题目描述:求一个算式的最大值与最小值. solution 按普通算式计算方法做,只不过要同时记住最大值和最小值而已. Convex H ...

  4. 2018 ICPC 徐州网络赛

    2018 ICPC 徐州网络赛 A. Hard to prepare 题目描述:\(n\)个数围成一个环,每个数是\(0\)~\(2^k-1\),相邻两个数的同或值不为零,问方案数. solution ...

  5. 2018 ICPC Asia Singapore Regional A. Largest Triangle (计算几何)

    题目链接:Kattis - largesttriangle Description Given \(N\) points on a \(2\)-dimensional space, determine ...

  6. 2018 ICPC Pacific Northwest Regional Contest I-Inversions 题解

    题目链接: 2018 ICPC Pacific Northwest Regional Contest - I-Inversions 题意 给出一个长度为\(n\)的序列,其中的数字介于0-k之间,为0 ...

  7. 2016 ICPC青岛站---k题 Finding Hotels(K-D树)

    题目链接 http://acm.hdu.edu.cn/showproblem.php?pid=5992 Problem Description There are N hotels all over ...

  8. 2018.9青岛网络预选赛(B)

    传送门:Problem(B) https://www.cnblogs.com/violet-acmer/p/9664805.html 参考资料: https://blog.csdn.net/qq_40 ...

  9. 2018.9青岛网络预选赛(K)

    传送门:Problem K https://www.cnblogs.com/violet-acmer/p/9664805.html 题意: 给你n个数,找出满足条件的最多的数的个数. 题解: 满足条件 ...

随机推荐

  1. ThinkPHP中header()无法发生跳转的解决办法

    一定要在header('Location:url')后加上exit()/die()才可以,特此记录.

  2. handlebars杂记

      1.{{{caption}}}三个花括号,可以解析 空格 变成 ‘空格’.   2.数据是posts:[{  }]数组时候,可以用{{posts.length}}取得其数组长度   3.handl ...

  3. 英特尔的Gen11集成显卡性能再次发力

    这是英特尔首个达到 1 TeraFLOP 算力的图形模块,与第九代酷睿移动版的性能相比,15W Ice Lake-U 在游戏测试场景中,平均帧速率的性能提升了 40%. 与同等的 AMD 产品相比,英 ...

  4. Linux20期学习笔记 Day2

    Linux系统进程状态及部分基础命令

  5. neutron网络实践

    一.虚拟机获取 ip: 用 namspace 隔离 DHCP 服务 Neutron 通过 dnsmasq 提供 DHCP 服务,而 dnsmasq 通过 Linux Network Namespace ...

  6. framebuffer测试程序

    /* framebuffer简单测试程序 网上转载 很多次 的程序 :-) */ #include <stdio.h> #include <stdlib.h> #include ...

  7. Big Data(六)用户权限实操&HDFS-API实操

    创建用户实操 1.创建用户god useradd god passwd god 2.设置ssh免密 ssh-copy-id -i id_dsa node02 3.修改hdfs-site.xml中的ss ...

  8. 对所有的webview添加userAgent

    在appdelegate中- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDicti ...

  9. CentOS源码编译安装MySQL 5.5.15

    CentOS源码编译安装MySQL 5.5.15   文章目录 [隐藏] 安装编译工具 下载源码 安装cmake和bison 编译安装MySQL 一些相关设置 安装编译工具 yum install g ...

  10. 美团点评SQL优化工具SQLAdvisor开源快捷部署

    美团点评SQL优化工具SQLAdvisor开源快捷部署 git clone https://github.com/Meituan-Dianping/SQLAdvisor.gityum install ...