Codeforces_835
A.比较两人总时间。
- #include<bits/stdc++.h>
- using namespace std;
- int s,v1,v2,t1,t2;
- int main()
- {
- ios::sync_with_stdio(false);
- cin >> s >> v1 >> v2 >> t1 >> t2;
- int x1 = s*v1+*t1,x2 = s*v2+*t2;
- if(x1 < x2) cout << "First" << endl;
- else if(x1 > x2) cout << "Second" << endl;
- else cout << "Friendship" << endl;
- return ;
- }
B.记录每个数值个9的差的个数,贪心大的。
- #include<bits/stdc++.h>
- using namespace std;
- int k,cnt[];
- string s;
- int main()
- {
- ios::sync_with_stdio(false);
- cin >> k >> s;
- int sum = ;
- for(int i = ;i < s.length();i++)
- {
- sum += s[i]-'';
- cnt[-s[i]+'']++;
- }
- int ans = ,now = ;
- while(sum < k)
- {
- while(cnt[now] == ) now--;
- cnt[now]--;
- sum += now;
- ans++;
- }
- cout << ans << endl;
- return ;
- }
C.给周期内每个时间点都开数组,二维前缀和。
- #include<bits/stdc++.h>
- using namespace std;
- int n,q,c,ans[][][] = {};
- int main()
- {
- ios::sync_with_stdio(false);
- cin >> n >> q >> c;
- for(int i = ;i <= n;i++)
- {
- int x,y,z;
- cin >> x >> y >> z;
- for(int j = ;j <= c;j++) ans[x][y][j] += (j+z)%(c+);
- }
- for(int k = ;k <= c;k++)
- {
- for(int i = ;i <= ;i++)
- {
- for(int j = ;j <= ;j++) ans[i][j][k] += ans[i][j-][k]+ans[i-][j][k]-ans[i-][j-][k];
- }
- }
- while(q--)
- {
- int t,x1,x2,y1,y2;
- cin >> t >> x1 >> y1 >> x2 >> y2;
- t %= (c+);
- cout << ans[x2][y2][t]-ans[x1-][y2][t]-ans[x2][y1-][t]+ans[x1-][y1-][t] << endl;
- }
- return ;
- }
D.区间dp。
- #include<bits/stdc++.h>
- using namespace std;
- string s;
- int dp[][] = {},ans[] = {};
- int main()
- {
- ios::sync_with_stdio();
- cin >> s;
- s = ' '+s;
- for(int i = ;i < s.length();i++) dp[i][i] = ;
- for(int i = ;i < s.length();i++)
- {
- if(s[i-] == s[i]) dp[i-][i] = ;
- }
- for(int len = ;len < s.length();len++)
- {
- for(int l = ;l+len- < s.length();l++)
- {
- int r = l+len-;
- if(s[l] != s[r] || !dp[l+][r-]) continue;
- dp[l][r] = dp[l][l+len/-]+;
- }
- }
- for(int i = ;i < s.length();i++)
- {
- for(int j = i;j < s.length();j++) ans[dp[i][j]]++;
- }
- for(int i = s.length()-;i >= ;i--) ans[i] += ans[i+];
- for(int i = ;i < s.length();i++) cout << ans[i] << " ";
- cout << endl;
- return ;
- }
E.因为有两个y,先把两个y划分进不同的组,把n个位置按位运算。每一位对应的值异或,统计只含一个y的位,10次。任取其中一位,对n个数划分成2块,之后对某一块少的二分找y的位置,9次。因为已经所有只含一个y的位,异或可得另一个y的位置。
- #include<bits/stdc++.h>
- using namespace std;
- int n,x,y;
- int ask(vector<int> v)
- {
- if(v.empty()) return ;
- cout << "? " << v.size();
- for(int i = ;i < v.size();i++) cout << " " << v[i];
- cout << endl;
- int x;
- cin >> x;
- return x;
- }
- int main()
- {
- ios::sync_with_stdio();
- cin >> n >> x >> y;
- int diff = ,diffb;
- for(int i = ;i < ;i++)
- {
- vector<int> v;
- for(int j = ;j <= n;j++)
- {
- if(j&(<<i)) v.push_back(j);
- }
- int t = ask(v);
- if(t == y || t == (x^y))
- {
- diff |= (<<i);
- diffb = i;
- }
- }
- vector<int> a,b;
- for(int i = ;i <= n;i++)
- {
- if(i&(<<diffb)) a.push_back(i);
- else b.push_back(i);
- }
- if(a.size() > b.size()) swap(a,b);
- int l = ,r = a.size()-;
- while(l < r)
- {
- int mid = (l+r)/;
- vector<int> v;
- for(int i = l;i <= mid;i++) v.push_back(a[i]);
- int t = ask(v);
- if(t == y ||t == (x^y)) r = mid;
- else l = mid+;
- }
- int ans1 = a[l],ans2 = ans1^diff;
- if(ans1 > ans2) swap(ans1,ans2);
- cout << "! " << ans1 << " " << ans2 << endl;
- return ;
- }
Codeforces_835的更多相关文章
随机推荐
- 1069 微博转发抽奖 (20分)C语言
小明 PAT 考了满分,高兴之余决定发起微博转发抽奖活动,从转发的网友中按顺序每隔 N 个人就发出一个红包.请你编写程序帮助他确定中奖名单. 输入格式: 输入第一行给出三个正整数 M(≤ 1000). ...
- Spring的一些基本概念(面试备用哦)
1.什么是Spring, 它有什么特点? 包括哪些内容? Spring是一个轻量级的控制反转(IoC)和面向切面(AOP)的容器框架. ◆ 轻量——从大小与开销两方面而言Spring都是轻量的.完整 ...
- Spark 配置参数
SparkConfiguration 这一章节来看看 Spark的相关配置. 并非仅仅能够应用于 SparkStreaming, 而是对于 Spark的各种类型都有支持. 各个不同. 其中中文参考链接 ...
- Java Collection集合中的iterator方法
Iterator接口的概述 /** * java.util.Iterator接口:选代器(对集合进行遍历) * 有两个常用的方法 * boolean hasNext() * 如果仍有元素可以迭代,则返 ...
- Thinkpad S440 I/O接口配置
HDMI 视频接口 SS USB3.0接口 电源接口 音频接口 网络接口 没有com口可以用USB口,然后安装一个USB转com口的驱动.
- 死磕面试 - Dubbo基础知识37问(必须掌握)
作为一个JAVA工程师,出去项目拿20k薪资以上,dubbo绝对是面试必问的,即使你对dubbo在项目架构上的作用不了解,但dubbo的基础知识也必须掌握. 整理分享一些面试中常会被问到的dubbo基 ...
- Python基础————文件操作
文件操作 4.1 文件基本操作 obj = open('路径',mode='模式',encoding='编码') # 表示要干嘛 读 还是写 obj.write() #写什么内容 obj.read() ...
- Java入门 - 语言基础 - 19.方法
原文地址:http://www.work100.net/training/java-method.html 更多教程:光束云 - 免费课程 方法 序号 文内章节 视频 1 概述 2 方法的定义 3 方 ...
- (数据科学学习手札73)盘点pandas 1.0.0中的新特性
本文对应脚本及数据已上传至我的Github仓库https://github.com/CNFeffery/DataScienceStudyNotes 1 简介 毫无疑问pandas已经成为基于Pytho ...
- 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 ...