A.比较两人总时间。

  1. #include<bits/stdc++.h>
  2. using namespace std;
  3.  
  4. int s,v1,v2,t1,t2;
  5.  
  6. int main()
  7. {
  8. ios::sync_with_stdio(false);
  9. cin >> s >> v1 >> v2 >> t1 >> t2;
  10. int x1 = s*v1+*t1,x2 = s*v2+*t2;
  11. if(x1 < x2) cout << "First" << endl;
  12. else if(x1 > x2) cout << "Second" << endl;
  13. else cout << "Friendship" << endl;
  14. return ;
  15. }

B.记录每个数值个9的差的个数,贪心大的。

  1. #include<bits/stdc++.h>
  2. using namespace std;
  3.  
  4. int k,cnt[];
  5. string s;
  6.  
  7. int main()
  8. {
  9. ios::sync_with_stdio(false);
  10. cin >> k >> s;
  11. int sum = ;
  12. for(int i = ;i < s.length();i++)
  13. {
  14. sum += s[i]-'';
  15. cnt[-s[i]+'']++;
  16. }
  17. int ans = ,now = ;
  18. while(sum < k)
  19. {
  20. while(cnt[now] == ) now--;
  21. cnt[now]--;
  22. sum += now;
  23. ans++;
  24. }
  25. cout << ans << endl;
  26. return ;
  27. }

C.给周期内每个时间点都开数组,二维前缀和。

  1. #include<bits/stdc++.h>
  2. using namespace std;
  3.  
  4. int n,q,c,ans[][][] = {};
  5.  
  6. int main()
  7. {
  8. ios::sync_with_stdio(false);
  9. cin >> n >> q >> c;
  10. for(int i = ;i <= n;i++)
  11. {
  12. int x,y,z;
  13. cin >> x >> y >> z;
  14. for(int j = ;j <= c;j++) ans[x][y][j] += (j+z)%(c+);
  15. }
  16. for(int k = ;k <= c;k++)
  17. {
  18. for(int i = ;i <= ;i++)
  19. {
  20. for(int j = ;j <= ;j++) ans[i][j][k] += ans[i][j-][k]+ans[i-][j][k]-ans[i-][j-][k];
  21. }
  22. }
  23. while(q--)
  24. {
  25. int t,x1,x2,y1,y2;
  26. cin >> t >> x1 >> y1 >> x2 >> y2;
  27. t %= (c+);
  28. cout << ans[x2][y2][t]-ans[x1-][y2][t]-ans[x2][y1-][t]+ans[x1-][y1-][t] << endl;
  29. }
  30. return ;
  31. }

D.区间dp。

  1. #include<bits/stdc++.h>
  2. using namespace std;
  3.  
  4. string s;
  5. int dp[][] = {},ans[] = {};
  6.  
  7. int main()
  8. {
  9. ios::sync_with_stdio();
  10. cin >> s;
  11. s = ' '+s;
  12. for(int i = ;i < s.length();i++) dp[i][i] = ;
  13. for(int i = ;i < s.length();i++)
  14. {
  15. if(s[i-] == s[i]) dp[i-][i] = ;
  16. }
  17. for(int len = ;len < s.length();len++)
  18. {
  19. for(int l = ;l+len- < s.length();l++)
  20. {
  21. int r = l+len-;
  22. if(s[l] != s[r] || !dp[l+][r-]) continue;
  23. dp[l][r] = dp[l][l+len/-]+;
  24. }
  25. }
  26. for(int i = ;i < s.length();i++)
  27. {
  28. for(int j = i;j < s.length();j++) ans[dp[i][j]]++;
  29. }
  30. for(int i = s.length()-;i >= ;i--) ans[i] += ans[i+];
  31. for(int i = ;i < s.length();i++) cout << ans[i] << " ";
  32. cout << endl;
  33. return ;
  34. }

E.因为有两个y,先把两个y划分进不同的组,把n个位置按位运算。每一位对应的值异或,统计只含一个y的位,10次。任取其中一位,对n个数划分成2块,之后对某一块少的二分找y的位置,9次。因为已经所有只含一个y的位,异或可得另一个y的位置。

  1. #include<bits/stdc++.h>
  2. using namespace std;
  3.  
  4. int n,x,y;
  5.  
  6. int ask(vector<int> v)
  7. {
  8. if(v.empty()) return ;
  9. cout << "? " << v.size();
  10. for(int i = ;i < v.size();i++) cout << " " << v[i];
  11. cout << endl;
  12. int x;
  13. cin >> x;
  14. return x;
  15. }
  16.  
  17. int main()
  18. {
  19. ios::sync_with_stdio();
  20. cin >> n >> x >> y;
  21. int diff = ,diffb;
  22. for(int i = ;i < ;i++)
  23. {
  24. vector<int> v;
  25. for(int j = ;j <= n;j++)
  26. {
  27. if(j&(<<i)) v.push_back(j);
  28. }
  29. int t = ask(v);
  30. if(t == y || t == (x^y))
  31. {
  32. diff |= (<<i);
  33. diffb = i;
  34. }
  35. }
  36. vector<int> a,b;
  37. for(int i = ;i <= n;i++)
  38. {
  39. if(i&(<<diffb)) a.push_back(i);
  40. else b.push_back(i);
  41. }
  42. if(a.size() > b.size()) swap(a,b);
  43. int l = ,r = a.size()-;
  44. while(l < r)
  45. {
  46. int mid = (l+r)/;
  47. vector<int> v;
  48. for(int i = l;i <= mid;i++) v.push_back(a[i]);
  49. int t = ask(v);
  50. if(t == y ||t == (x^y)) r = mid;
  51. else l = mid+;
  52. }
  53. int ans1 = a[l],ans2 = ans1^diff;
  54. if(ans1 > ans2) swap(ans1,ans2);
  55. cout << "! " << ans1 << " " << ans2 << endl;
  56. return ;
  57. }

Codeforces_835的更多相关文章

随机推荐

  1. 1069 微博转发抽奖 (20分)C语言

    小明 PAT 考了满分,高兴之余决定发起微博转发抽奖活动,从转发的网友中按顺序每隔 N 个人就发出一个红包.请你编写程序帮助他确定中奖名单. 输入格式: 输入第一行给出三个正整数 M(≤ 1000). ...

  2. Spring的一些基本概念(面试备用哦)

    1.什么是Spring, 它有什么特点? 包括哪些内容? Spring是一个轻量级的控制反转(IoC)和面向切面(AOP)的容器框架. ◆  轻量——从大小与开销两方面而言Spring都是轻量的.完整 ...

  3. Spark 配置参数

    SparkConfiguration 这一章节来看看 Spark的相关配置. 并非仅仅能够应用于 SparkStreaming, 而是对于 Spark的各种类型都有支持. 各个不同. 其中中文参考链接 ...

  4. Java Collection集合中的iterator方法

    Iterator接口的概述 /** * java.util.Iterator接口:选代器(对集合进行遍历) * 有两个常用的方法 * boolean hasNext() * 如果仍有元素可以迭代,则返 ...

  5. Thinkpad S440 I/O接口配置

    HDMI 视频接口 SS USB3.0接口 电源接口 音频接口 网络接口 没有com口可以用USB口,然后安装一个USB转com口的驱动.

  6. 死磕面试 - Dubbo基础知识37问(必须掌握)

    作为一个JAVA工程师,出去项目拿20k薪资以上,dubbo绝对是面试必问的,即使你对dubbo在项目架构上的作用不了解,但dubbo的基础知识也必须掌握. 整理分享一些面试中常会被问到的dubbo基 ...

  7. Python基础————文件操作

    文件操作 4.1 文件基本操作 obj = open('路径',mode='模式',encoding='编码') # 表示要干嘛 读 还是写 obj.write() #写什么内容 obj.read() ...

  8. Java入门 - 语言基础 - 19.方法

    原文地址:http://www.work100.net/training/java-method.html 更多教程:光束云 - 免费课程 方法 序号 文内章节 视频 1 概述 2 方法的定义 3 方 ...

  9. (数据科学学习手札73)盘点pandas 1.0.0中的新特性

    本文对应脚本及数据已上传至我的Github仓库https://github.com/CNFeffery/DataScienceStudyNotes 1 简介 毫无疑问pandas已经成为基于Pytho ...

  10. Oracle GoldenGate Best Practices: Active-Active Configuration with DML Auto CDR

    Executive Overview This document is an introduction to Oracle GoldenGate (DIPC remote agent)’s best ...