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的更多相关文章
随机推荐
- 1044 火星数字 (20 分)C语言
火星人是以 13 进制计数的: 地球人的 0 被火星人称为 tret. 地球人数字 1 到 12 的火星文分别为:jan, feb, mar, apr, may, jun, jly, aug, sep ...
- 阿里云函数计算 .NET Core 初体验
体验了一波阿里云函数计算, 已支持 .NET Core 2.1, 那么按照惯例, 来写个 "Hello World" 吧. 作者注: 开发环境 Windows 10 & V ...
- 30.strftime参数
附:strftime参数 strftime(format[, tuple]) -> string 将指定的struct_time(默认为当前时间),根据指定的格式化字符串输出 python中时间 ...
- file_get_contents函数获取不到数据的一种情况
问题: file_get_contents($url) 获取不到数据,尽管URL地址正确,函数使用正确.如下代码 $url = "https://www.baidu.com"; ...
- Springboot2.1.1下的自定义拦截器而静态资源不能访问的问题
1.项目结构 2.自定义拦截器 public class LoginHandlerlnterceptor implements HandlerInterceptor { //目标方法执行之前 @Ove ...
- 关于django中的get_or_create方法的坑
最近在项目中发现了这样的一个坑,那就是我们的需求是不能添加一个相同的对象到数据库中,就通过某些字段的值组合成唯一值到数据库中去查找数据,如果没有找到对象,那就创建一条新的数据库记录,而刚好django ...
- vue基础中的注意事项,以及一些学习心得
vue中你不知道的东西.以及注意事项 v-html 使用 v-html的时候该指令中的值会覆盖绑定标签中原有的值,且使用v-html的时候不要将他设置为给用户提供内容的地方,因为v-html很容易被X ...
- 单调队列优化 dp
The only difference between easy and hard versions is the constraints. Vova likes pictures with kitt ...
- wannafly camp day1
题目描述: 恬恬的生日临近了.宇扬给她准备了一个大 蛋糕. 正如往常一样,宇扬在蛋糕上插了nnn支蜡烛,并把蛋糕分为mmm个区域.因为某种原因,他必须把第iii根蜡烛插在第aia\_iai个区域或第 ...
- java Random类(API)
一.过程 1.导包 2.实例化 3.使用(类的成员方法) 二.作用 生成随机数,与python中random 相似 三.常用方法 1.nextInt(),随机生成int数据类型范围的数 2.nextI ...