Pizza Serparation

#include<stdio.h>
#include<string.h>
#include<stdlib.h>
#include<vector>
#include<algorithm>
#include<iostream>
#include<map>
#include<queue>
using std::vector;
using std::queue;
using std::map;
using std::sort;
using std::string;
#define read(x) scanf("%d",&x)
#define reads(x) scanf("%s",x) int cmp(const void * x, const void * y) {
#define datatype int
datatype dx = *((datatype *)(x)), dy = *((datatype *)(y));
//x < y
return dx > dy ? : -;
#undef datatype
} int a[], nex[];
int main() {
#ifndef ONLINE_JUDGE
freopen("input.txt", "r", stdin);
#endif
int n;
read(n);
for (int i = ; i < n; i++) {
read(a[i]);
nex[i] = i + ;
}
nex[n - ] = ;
int ans = 0x3FFFFFFF;
for (int i = ; i < n; i++) {
int sum = ;
for (int j = i;; j = nex[j]) {
sum += a[j];
if (sum >= ) break;
}
if ( * (sum - ) < ans) ans = * (sum - );
}
printf("%d\n", ans);
return ;
}

XK Segments

STL真是手残拯救者

#include<stdio.h>
#include<string.h>
#include<stdlib.h>
#include<vector>
#include<algorithm>
#include<iostream>
#include<map>
#include<queue>
#include<string>
using std::vector;
using std::queue;
using std::map;
using std::sort;
using std::string;
using std::lower_bound;
using std::upper_bound;
#define read(x) scanf("%d", &x)
#define reads(x) scanf("%s", x)
#define write(x) printf("%d ", x)
#define writes(x) printf("%s ", x)
#define writeln(x) printf("%d\n", x)
#define writesln(x) printf("%s\n", x)
typedef long long llint;
/*data structure*/ /*data structure*/
int cmp(const void * x, const void * y) {
#define datatype int
datatype dx = *((datatype *)(x)), dy = *((datatype *)(y));
//x < y
return dx > dy ? : -;
#undef datatype
}
/*global variable*/
map<llint, int> mp;
vector<llint> v;
int sum[];
/*global variable*/
int main() {
#ifndef ONLINE_JUDGE
freopen("input.txt", "r", stdin);
#endif
int n;
llint a, ap, h, l, b, x, k;
while (scanf("%d%lld%lld", &n, &x, &k) != EOF) {
mp.clear();
v.clear();
for (int i = ; i < n; i++) {
scanf("%lld", &a);
if (mp.find(a) == mp.end()) v.push_back(a);
mp[a]++;
}
sort(v.begin(), v.end());
sum[] = mp[v[]];
for (int i = ; i < v.size(); i++) sum[i] = sum[i - ] + mp[v[i]];
llint ans = ;
for (int i = ; i < v.size(); i++) {
a = v[i];
if (a % x == ) ap = a;
else ap = a - a % x + x;
if (k == ) {
h = ap - ;
l = a;
} else {
ap += x * (k - );
l = ap;
h = ap + x - ;
}
if (l > h) continue;
int s = lower_bound(v.begin(), v.end(), l) - v.begin(), e = lower_bound(v.begin(), v.end(), h) - v.begin();
if (e == v.end() - v.begin()) e--;
if (v[e] > h) e--;
if (s == v.end() - v.begin()) continue;
ans += (llint)mp[a] * (llint)(sum[e] - sum[s] + mp[v[s]]);
}
printf("%lld\n", ans);
}
return ;
}

Square Subsets

首先,其中本来就是完全平方数的数,爱取多少取多少,不影响结果,只需最终结果乘以2^a[i]

对于不是完全平方数的数,只需关心其取了奇数个还是偶数个,具体数目不影响结果,因此可以看成只取0个或1个,最终结果乘以2^(a[i]-1)。

将1-70的数分解质因数,记录每个数的各个因子有奇数个还是偶数个。

1-70间的质数共19个,用0-2^19-1表示所有状态,第i为为1表示第i个质数有奇数个,为0表示有偶数个。

dp[i]表示达到i这种质因子奇偶状态的方法数,dp[0]表示完全平方数的方法数。

最终结果减1,去掉空集。

#include<stdio.h>
#include<string.h>
#include<stdlib.h>
#include<vector>
#include<algorithm>
#include<iostream>
#include<map>
#include<queue>
#include<string>
using std::vector;
using std::queue;
using std::map;
using std::sort;
using std::string;
using std::lower_bound;
using std::upper_bound;
#define read(x) scanf("%d", &x)
#define reads(x) scanf("%s", x)
#define write(x) printf("%d ", x)
#define writes(x) printf("%s ", x)
#define writeln(x) printf("%d\n", x)
#define writesln(x) printf("%s\n", x)
#define fillchar(x, a) memset(x, a, sizeof(x))
typedef long long llint;
/*data structure*/ /*data structure*/
int cmp(const void * x, const void * y) {
#define datatype int
datatype dx = *((datatype *)(x)), dy = *((datatype *)(y));
//x < y
return dx > dy ? : -;
#undef datatype
}
/*global variable*/
const int p[] = {, , , , , , , , , , , , , , , , , , };
const llint mod = ;
int a[], v[][];
llint dp[][ << ];
/*global variable*/
int main() {
#ifndef ONLINE_JUDGE
freopen("input.txt", "r", stdin);
#endif
int n, x;
read(n);
fillchar(a, );
fillchar(v, );
for (int i = ; i < n; i++) {
read(x);
a[x]++;
}
int multp = ;
for (int i = ; i <= ; i++) {
multp += a[i * i];
a[i * i] = ;
}
for (int i = ; i <= ; i++) {
if (a[i]) multp += (a[i] - );
}
for (int i = ; i <= ; i++) {
x = i;
for (int j = ; j < ; j++) {
while (x % p[j] == ) {
v[i][j] = - v[i][j];
x /= p[j];
}
}
}
fillchar(dp, );
dp[][] = ;
int last = , cur;
for (int i = ; i <= ; i++) {
if (a[i] == ) continue;
cur = - last;
for (int j = ; j < ( << ); j++) dp[cur][j] = ;
for (int j = ; j < ( << ); j++) {
int state = j;
if (dp[last][state] == ) continue;
for (int k = ; k < ; k++) {
state ^= (v[i][k] << k);
}
dp[cur][state] = (dp[cur][state] + dp[last][j]) % mod;
}
for (int j = ; j < ( << ); j++) {
dp[cur][j] = (dp[cur][j] + dp[last][j]) % mod;
}
last = cur;
}
llint ans = dp[last][];
for (int i = ; i < multp; i++) {
ans = ans * % mod;
}
printf("%lld\n", ans - );
return ;
}

String Mark

设f(s)为用字符串a组合能产生比s小的字符串的个数,答案为f(b)-f(a)-1,一位一位算就可以了。

#include<stdio.h>
#include<string.h>
#include<stdlib.h>
#include<vector>
#include<algorithm>
#include<iostream>
#include<map>
#include<queue>
#include<string>
#include<functional>
#include<iostream>
using std::priority_queue;
using std::vector;
using std::queue;
using std::map;
using std::sort;
using std::string;
using std::lower_bound;
using std::upper_bound;
using std::cin;
using std::cout;
using std::endl;
#define fillchar(x, a) memset(x, a, sizeof(x))
typedef long long lint;
/*data structure*/ /*data structure*/
int cmp(const void * x, const void * y) {
#define datatype int
datatype dx = *((datatype *)(x)), dy = *((datatype *)(y));
//x < y
return dx > dy ? : -;
#undef datatype
}
/*global variable*/
char a[], b[];
lint fac[], ifac[];
int cnt[], n;
const lint mod = ;
/*global variable*/
/*function*/
inline lint pow(lint a, lint b, lint p) {
lint rtn = ;
while (b) {
if (b & ) rtn = rtn * a % p;
a = a * a % p;
b >>= ;
}
return rtn;
}
lint f(char * s) {
fillchar(cnt, );
for (int i = ; i < n; i++) cnt[a[i] - 'a']++;
lint div = ;
for (int i = ; i < ; i++) div = div * ifac[cnt[i]] % mod;
lint rtn = ;
for (int i = ; i < n; i++) {
for (int j = ; j < s[i] - 'a'; j++) {
if (cnt[j]) {
rtn = (rtn + fac[n - i - ] * cnt[j] % mod * div % mod) % mod;
}
}
if (cnt[s[i] - 'a'] == ) return rtn;
div = div * cnt[s[i] - 'a'] % mod;
cnt[s[i] - 'a']--;
}
return rtn;
}
/*function*/
int main() {
#ifndef ONLINE_JUDGE
freopen("input.txt", "r", stdin);
#endif
std::ios::sync_with_stdio(), cin.tie();
cin >> a >> b;
n = strlen(a);
fac[] = ifac[] = ;
for (int i = ; i <= n; i++) {
fac[i] = fac[i - ] * i % mod;
ifac[i] = pow(fac[i], mod - , mod);
}
cout << (f(b) - f(a) - + mod) % mod << endl;
return ;
}

Eyes Closed

每个线段里随机选个数,选出来的数期望为线段里的数的平均数,设为a。对于长度为l的线段里的一个数字x,其保持不变的概率为(l-1)/l,被选出来交换的概率为1/l,则其期望为ex=x*(l-1)/l+a/l,即操作后线段里每个数字的期望为原数字乘以一个常数再加一个常数,可以用线段树来实现这个操作,把lazy标记分成两部分即可。

#include<stdio.h>
#include<string.h>
#include<stdlib.h>
#include<vector>
#include<algorithm>
#include<iostream>
#include<map>
#include<queue>
#include<string>
using std::vector;
using std::queue;
using std::map;
using std::sort;
using std::string;
using std::lower_bound;
using std::upper_bound;
#define read(x) scanf("%d", &x)
#define reads(x) scanf("%s", x)
#define write(x) printf("%d ", x)
#define writes(x) printf("%s ", x)
#define writeln(x) printf("%d\n", x)
#define writesln(x) printf("%s\n", x)
#define fillchar(x, a) memset(x, a, sizeof(x))
typedef long long llint;
/*data structure*/
template <class T> class SegmentTree {
public:
T dat, lazym, lazyp;
int leftBorder, rightBorder, mid;
SegmentTree * leftSon, * rightSon;
SegmentTree() {
leftBorder = rightBorder = -;
leftSon = rightSon = NULL;
}
void pushdown();
void pushup();
void Build(T *, int, int);
void Modify(int, int, T, T);
T Query(int, int);
void Free();
};
template<class T> void SegmentTree<T>::pushdown() {
if ((lazym != || lazyp != (T)) && leftBorder != rightBorder) {
leftSon->dat = leftSon->dat * lazym + lazyp * (leftSon->rightBorder - leftSon->leftBorder + );
rightSon->dat = rightSon->dat * lazym + lazyp * (rightSon->rightBorder - rightSon->leftBorder + );
leftSon->lazym *= lazym;
leftSon->lazyp = leftSon->lazyp * lazym + lazyp;
rightSon->lazym *= lazym;
rightSon->lazyp = rightSon->lazyp * lazym + lazyp;
}
lazym = (T);
lazyp = (T);
}
template<class T> void SegmentTree<T>::pushup() {
dat = leftSon->dat + rightSon->dat;
}
template<class T> void SegmentTree<T>::Build(T * S, int l, int r) {
if (l > r) {
return;
}
lazym = (T);
lazyp = (T);
leftBorder = l;
rightBorder = r;
mid = (leftBorder + rightBorder) >> ;
if (l == r) {
dat = S[l];
return;
}
leftSon = new SegmentTree;
leftSon->Build(S, l, mid);
rightSon = new SegmentTree;
rightSon->Build(S, mid + , r);
pushup();
}
template<class T> void SegmentTree<T>::Modify(int l, int r, T mult, T plus) {
if (l > r || l < leftBorder || rightBorder < r) {
return;
}
if (leftBorder == l && rightBorder == r) {
dat = dat * mult + plus * (rightBorder - leftBorder + );
lazym *= mult;
lazyp = lazyp * mult + plus;
return;
}
pushdown();
if (r <= mid) {
leftSon->Modify(l, r, mult, plus);
} else if (mid < l) {
rightSon->Modify(l, r, mult, plus);
} else {
leftSon->Modify(l, mid, mult, plus);
rightSon->Modify(mid + , r, mult, plus);
}
pushup();
}
template<class T> T SegmentTree<T>::Query(int l, int r) {
if (l > r || l < leftBorder || rightBorder < r) {
return dat;
}
pushdown();
if (l == leftBorder && r == rightBorder) {
return dat;
}
if (r <= mid) {
return leftSon->Query(l, r);
} else if (mid < l) {
return rightSon->Query(l, r);
} else {
return leftSon->Query(l, mid) + rightSon->Query(mid + , r);
}
}
template<class T> void SegmentTree<T>::Free() {
if (leftSon != NULL) {
leftSon->Free();
}
if (rightSon != NULL) {
rightSon->Free();
}
delete leftSon;
delete rightSon;
}
/*data structure*/
int cmp(const void * x, const void * y) {
#define datatype int
datatype dx = *((datatype *)(x)), dy = *((datatype *)(y));
//x < y
return dx > dy ? : -;
#undef datatype
}
/*global variable*/
SegmentTree<double> st;
double a[];
/*global variable*/
int main() {
#ifndef ONLINE_JUDGE
freopen("input.txt", "r", stdin);
#endif
int n, q;
read(n);
read(q);
for (int i = ; i < n; i++) scanf("%lf", &a[i]);
st.Build(a, , n - );
int t, l1, l2, l, r1, r2, r;
for (int i = ; i < q; i++) {
read(t);
if (t == ) {
read(l1);
read(r1);
read(l2);
read(r2);
l1--, r1--, l2--, r2--;
double sum1 = st.Query(l1, r1), sum2 = st.Query(l2, r2);
double ave1 = sum1 / (r1 - l1 + 1.0), ave2 = sum2 / (r2 - l2 + 1.0);
st.Modify(l1, r1, (r1 - l1) / (r1 - l1 + 1.0), ave2 / (r1 - l1 + 1.0));
st.Modify(l2, r2, (r2 - l2) / (r2 - l2 + 1.0), ave1 / (r2 - l2 + 1.0));
} else {
read(l);
read(r);
l--, r--;
double ans = st.Query(l, r);
printf("%.7lf\n", ans);
}
}
return ;
}

Codeforces Round #448的更多相关文章

  1. Codeforces Round #448 C. Square Subsets

    题目链接 Codeforces Round #448 C. Square Subsets 题解 质因数 *质因数 = 平方数,问题转化成求异或方程组解的个数 求出答案就是\(2^{自由元-1}\) , ...

  2. Codeforces Round #448(Div.2) Editorial ABC

    被B的0的情况从头卡到尾.导致没看C,心情炸裂又掉分了. A. Pizza Separation time limit per test 1 second memory limit per test ...

  3. Codeforces Round #448 (Div. 2) B

    题目描述有点小坑,ij其实是没有先后的 并且y并不一定存在于a中 判断y的个数和所给数组无关 对于2 - 7来说 中间满足%2==0的y一共有3个 2 4 6 这样 可以看出对于每个数字a 都能够二分 ...

  4. Codeforces Round #448 (Div. 2)C. Square Subsets

    可以用状压dp,也可以用线型基,但是状压dp没看台懂... 线型基的重要性质 性质一:最高位1的位置互不相同 性质二:任意一个可以用这些向量组合出的向量x,组合方式唯一 性质三:线性基的任意一个子集异 ...

  5. Codeforces Round #448 (Div. 2) B. XK Segments【二分搜索/排序/查找合法的数在哪些不同区间的区间数目】

    B. XK Segments time limit per test 1 second memory limit per test 256 megabytes input standard input ...

  6. Codeforces Round #448 (Div. 2) A. Pizza Separation【前缀和/枚举/将圆(披萨)分为连续的两块使其差最小】

    A. Pizza Separation time limit per test 1 second memory limit per test 256 megabytes input standard ...

  7. Codeforces Round #366 (Div. 2) ABC

    Codeforces Round #366 (Div. 2) A I hate that I love that I hate it水题 #I hate that I love that I hate ...

  8. Codeforces Round #354 (Div. 2) ABCD

    Codeforces Round #354 (Div. 2) Problems     # Name     A Nicholas and Permutation standard input/out ...

  9. Codeforces Round #368 (Div. 2)

    直达–>Codeforces Round #368 (Div. 2) A Brain’s Photos 给你一个NxM的矩阵,一个字母代表一种颜色,如果有”C”,”M”,”Y”三种中任意一种就输 ...

随机推荐

  1. C# 聚合数据借口发短信的使用

    using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; usin ...

  2. 记录:Ubuntu下安装SQL Developer

    安装JDK. 用的Ubuntu18.04,已经自带JDK了. 下载SQL Developer. 官网链接:http://www.oracle.com/technetwork/developer-too ...

  3. mint-ui 取值

    //slots:[{values: ['年假', '事假', '病假', '婚假', '其他']}], slots:[{values: []}], onValuesChange(picker,valu ...

  4. 【2】Django安装

    **万物负阴而抱阳,冲气以为和 ** ——老子<道德经> 我们静下心态,开始我们的Django之旅 本节内容 Django的安装 安装结果验证 了解官方文档 1. 安装Django 我们强 ...

  5. Java设计模式之 — 单例(Singleton)

    转载请注明出处:http://blog.csdn.net/guolin_blog/article/details/8860649 写软件的时候经常需要用到打印日志功能,可以帮助你调试和定位问题,项目上 ...

  6. vue中的slot理解和使用

    最近被vue 搞得一塌糊涂,理解的比较慢,工作进度进度要求太快,需求理解不明,造成了很大的压力. 在理解Vue中的Slot的时候看了网上的相关内容,看了半天没看到明白说的是什么,然后自己就安装了vue ...

  7. [Angular] Upgrading to RxJS v6

    This is just a learning blog post, check out the talk. 1. Custom pipeable operators: Custom pipeable ...

  8. HDU 1788 Chinese remainder theorem again 中国剩余定理

    题意: 给定n,AA 以下n个数m1,m2···mn 则有n条方程 res % m1 = m1-AA res % m2 = m2-AA 问res的最小值 直接上剩余定理,嘿嘿 #include< ...

  9. Codeforces Round #350 (Div. 2) E. Correct Bracket Sequence Editor 线段树模拟

    E. Correct Bracket Sequence Editor   Recently Polycarp started to develop a text editor that works o ...

  10. GNU TeXmacs 1.99.8 发布,所见即所得科学编辑器(看看老实的GUI)

    GNU TeXmacs 1.99.8 已发布,这是一个支持各种数学公式的所见即所得编辑器,可以用来编辑文本.图形.数学.交互内容,它的界面非常友好,并且内置高质量的排版引擎. 更新内容: bug 修复 ...