Codeforces 975 前缀和二分算存活人数 思维离直线速度相同判平行
A
/* Huyyt */
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
string a[];
int num[];
map<ll, int> mp;
int main()
{
int n;
cin >> n;
for (int i = ; i <= n; i++)
{
cin >> a[i];
}
int anser = ;
for (int i = ; i <= n; i++)
{
memset(num, , sizeof(num));
int now = ;
for (int j = ; j < a[i].size(); j++)
{
int cur = a[i][j] - 'a';
if (!num[cur])
{
num[cur] = ;
now += (1LL << cur);
}
}
if (!mp[now])
{
anser++;
mp[now]++;
}
}
cout << anser << endl;
}
B
/* Huyyt */
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
string a[];
ll num[];
ll ans[];
int main()
{
ll anser = ;
for (int i = ; i <= ; i++)
{
cin >> num[i];
}
for (int i = ; i <= ; i++)
{
ll now = ;
ll has;
for (int j = ; j <= ; j++)
{
ans[j] = num[j];
}
if (ans[i] == )
{
continue;
}
if (ans[i] >= )
{
ll bei = ans[i] / ;
has = ans[i] - * bei;
ans[i] = ;
for (int j = ; j <= ; j++)
{
ans[j] += bei;
}
int cur = i + ;
if (cur > )
{
cur -= ;
}
while (has)
{
ans[cur]++;
cur++;
if (cur > )
{
cur -= ;
}
has--;
}
}
else
{
has = ans[i];
ans[i] = ;
int cur = i + ;
if (cur > )
{
cur -= ;
}
while (has)
{
ans[cur]++;
cur++;
if (cur > )
{
cur -= ;
}
has--;
}
}
for (int j = ; j <= ; j++)
{
if (ans[j] % == )
{
now += ans[j];
}
}
anser = max(now, anser);
}
cout << anser << endl;
}
C
前缀和+二分
/* Huyyt */
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
ll n, m;
ll num[];
int getans(ll x)
{
int l = , r = n;
int mid, ans;
while (l <= r)
{
mid = (l + r) / ;
if (num[mid] > x)
{
ans = mid;
r = mid - ;
}
else
{
l = mid + ;
}
}
return ans;
}
int main()
{
ll now = ;
ll q;
cin >> n >> m;
for (int i = ; i <= n; i++)
{
cin >> num[i];
num[i] += num[i - ];
}
for (int i = ; i <= m; i++)
{
cin >> q;
now += q;
if (now >= num[n])
{
cout << n << endl;
now = ;
}
else
{
cout << n + - getans(now) << endl;
}
}
}
D
将点以离开原来所在直线的速度排序 相同速度的为一团
当且仅当两个速度方向一样(Vxi=Vxj Vyi=Vyj)的时候不会相交
/* Huyyt */
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll cheng = ;
ll dian[];
ll k, anser;
ll sum = ;
ll kb;
ll vx, vy;
map<ll, ll> mp;
int main()
{
int n, m;
cin >> n;
cin >> k >> kb;
for (int i = ; i <= n; i++)
{
cin >> kb >> vx >> vy;
sum = 1LL * vx * (1LL * cheng + );
sum += vy;
anser -= 2LL * mp[sum];
mp[sum]++;
dian[i] = 1LL * vx * k - vy;
}
sum = ;
sort(dian + , dian + n + );
for (int i = ; i <= n; i++)
{
if (dian[i] == dian[i - ])
{
sum++;
}
else
{
anser += 1LL * sum * (sum - );
sum = ;
}
}
ll add = 1LL * sum * (sum - );
anser += add;
cout << anser << endl;
}
Codeforces 975 前缀和二分算存活人数 思维离直线速度相同判平行的更多相关文章
- Codeforces 948 数论推导 融雪前缀和二分check 01字典树带删除
A. 全部空的放狗 B. 先O(NLOGNLOGN)处理出一个合数质因数中最大的质数是多少 因为p1 x1 x2的关系是 x2是p在x1之上的最小倍数 所以x1的范围是[x2-p+1,x2-1]要使最 ...
- Codeforces 1090J $kmp+hash+$二分
题意 给出两个字符串\(s\)和\(t\),设\(S\)为\(s\)的任意一个非空前缀,\(T\)为\(t\)的任意一个非空前缀,问\(S+T\)有多少种不同的可能. Solution 看了一圈,感觉 ...
- [Codeforces 1199C]MP3(离散化+二分答案)
[Codeforces 1199C]MP3(离散化+二分答案) 题面 给出一个长度为n的序列\(a_i\)和常数I,定义一次操作[l,r]可以把序列中<l的数全部变成l,>r的数全部变成r ...
- Glider(前缀和+二分)
题目链接:Glider Gym-101911B 解题分析:下落的高度一定,是h.在没有气流的地方每秒下落1:所以可以转化为经过无气流地带的时间总长为h. 那么很显然从一个有气流地带的开始,选择下落,那 ...
- Acwing:102. 最佳牛围栏(前缀和 + 二分)
农夫约翰的农场由 NN 块田地组成,每块地里都有一定数量的牛,其数量不会少于1头,也不会超过2000头. 约翰希望用围栏将一部分连续的田地围起来,并使得围起来的区域内每块地包含的牛的数量的平均值达到最 ...
- Educational Codeforces Round 11 C. Hard Process 前缀和+二分
题目链接: http://codeforces.com/contest/660/problem/C 题意: 将最多k个0变成1,使得连续的1的个数最大 题解: 二分连续的1的个数x.用前缀和判断区间[ ...
- Codeforces Global Round 2 D 差分 + 前缀和 + 二分
https://codeforces.com/contest/1119/problem/D 题意 有n个数组,每个数组大小为\(10^{18}+1\)且为等差数列,给出n个数组的\(s[i]\),q次 ...
- Codeforces 954 dijsktra 离散化矩阵快速幂DP 前缀和二分check
A B C D 给你一个联通图 给定S,T 要求你加一条边使得ST的最短距离不会减少 问你有多少种方法 因为N<=1000 所以N^2枚举边数 迪杰斯特拉两次 求出Sdis 和 Tdis 如果d ...
- CodeForces - 948C(前缀和 + 二分)
链接:CodeForces - 948C 题意:N天,每天生产一堆雪体积 V[i] ,每天每堆雪融化 T[i],问每天融化了多少雪. 题解:对 T 求前缀和,求每一堆雪能熬过多少天,再记录一下多余的就 ...
随机推荐
- 统计学_Wilcoxon signed-rank test(python脚本)
python机器学习-乳腺癌细胞挖掘(博主亲自录制视频) https://study.163.com/course/introduction.htm?courseId=1005269003&u ...
- Retrofitting Analysis
Retrofitting Analysis To figure out the process of retrofitting[1] objective updating, we do the fol ...
- 初始化EPT
struct eptp_bits { unsigned memory_type :; /* 0: UC uncacheable, 6: WB writeback */ unsigned pagewal ...
- 两个 Activity 之间跳转时必然会执行的是哪几个方法?
一般情况下比如说有两个 activity,分别叫 A,B,当在 A 里面激活 B 组件的时候, A 会调用 onPause()方法,然后 B 调用 onCreate() ,onStart(), onR ...
- ControlTemplate in WPF —— Shared in all file
<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" x ...
- C# 给某个方法设定执行超时时间-2
var response = RunTaskWithTimeout<ReturnType>( (Func<ReturnType>)); /// <summary> ...
- LinkedHashSet 的实现原理
原文:http://wiki.jikexueyuan.com/project/java-collection/linkedhashset.html LinkedHashSet 概述 思考了好久,到底要 ...
- java:JSP(JSPWeb.xml的配置,动态和静态导入JSP文件,重定项和请求转发,使用JSP实现数据库的增删改查实例)
1.JSP的配置: <%@ page language="java" import="java.util.*" pageEncoding="UT ...
- vsftp新建用户及目录时遇到的坑
1.有关vsftp配置及用户权限设置,请参考: http://blog.sina.com.cn/s/blog_3edc5e2e0102vzv8.html 2.需求:公司另一部门要求单独建一目录,来存在 ...
- jquery实现分页效果
通过jq实现分页的原理如下:将所有条数加载到页面中,根据每页放特定条数(例如 5 条)获取jquery对象索引,使部分条数显示,其他条数隐藏. 前提:引入jquery.js 代码 <!DOCTY ...