CF1151div2(Round 553)

思路题大赛

A

少考虑了一种情况,到死没想到

B

貌似我随机化50000次,没找到就无解貌似也过了

感觉随随便便乱搞+分类讨论都可以过的样子

#include<cstdio>
#include<iostream>
#include<queue>
#include<algorithm>
#include<cstring>
#include<cctype>
#include<vector>
#include<ctime>
#include<cmath>
#define LL long long
#define pii pair<int,int>
#define mk make_pair
#define fi first
#define se second
using namespace std;
const int N = 505;
inline int read(){
int v = 0,c = 1;char ch = getchar();
while(!isdigit(ch)){
if(ch == '-') c = -1;
ch = getchar();
}
while(isdigit(ch)){
v = v * 10 + ch - 48;
ch = getchar();
}
return v * c;
}
int a[N][N];
int b[N][N];
int tot;
int s[N];
int n,m;
inline bool pan(){
for(int i = 1;i <= n;++i)
for(int j = 1;j <= n;++j)
if(b[i][j] != 1) return 0;
return 1;
}
inline bool check(){
if(pan()){
if(n & 1){
for(int i = 1;i <= n;++i) s[++tot] = 1;
return 1;
}
else return 0;
} }
int main(){
srand(time(0));
n = read(),m = read();
for(int i = 1;i <= n;++i) for(int j = 1;j <= m;++j) a[i][j] = read();
for(int t = 1;t <= 50000;++t){
int now = 0;
for(int i = 1;i < n;++i) s[i] = rand() % m + 1,now ^= a[i][s[i]];
for(int i = 1;i <= m;++i){
if((now ^ a[n][i]) != 0){
s[n] = i;
printf("TAK\n");
for(int j = 1;j <= n;++j) printf("%d ",s[j]);
return 0;
}
}
}
printf("NIE\n");
return 0;
}

C

辣鸡CF连__int128都不支持

我们将所有的区间分成log块去考虑

每一块的内部其实都是等差数列

我们可以用等差数列求和公式

对于\(L,R\)就求一下前缀和

另外项数可能很大,一定要%mod(我就是因为这个WA的)

#include<cstdio>
#include<iostream>
#include<queue>
#include<algorithm>
#include<cstring>
#include<cctype>
#include<vector>
#include<ctime>
#include<cmath>
#define LL long long
#define pii pair<int,int>
#define mk make_pair
#define fi first
#define se second
using namespace std;
const LL mod = 1e9 + 7;
inline LL read(){
LL v = 0,c = 1;char ch = getchar();
while(!isdigit(ch)){
if(ch == '-') c = -1;
ch = getchar();
}
while(isdigit(ch)){
v = v * 10 + ch - 48;
ch = getchar();
}
return v * c;
}
LL L,R;
LL sum[129];
LL shou[129];
inline LL quick(LL x,LL y){
LL res = 1;
while(y){
if(y & 1) res = res * x % mod;
y >>= 1;
x = x * x % mod;
}
return res;
}
LL inv2 = quick(2,mod - 2);
inline LL work(LL x){
if(x == 0) return 0;
LL cnt = 0;
LL gg = 0;
LL ans = 0;
while(gg + (1ll << cnt) <= x){
ans = (ans + sum[cnt]) % mod;
gg += (1ll << cnt);
cnt++;
}
if(gg != x){
LL rest = (x - gg) % mod;
LL rail = (shou[cnt] + (rest - 1) * 2 % mod) % mod;
ans = (ans + (shou[cnt] + rail) % mod * rest % mod * inv2 % mod) % mod;
}
return ans;
}
int main(){
L = read(),R = read();
LL now = 0;
LL base = 0;
LL ji = 1;
LL ou = 2;
long long rr = R;
do{
rr -= (1ll << base);
// printf("%lld\n",rr);
if(base & 1){
shou[base] = ou;
sum[base] = (ou + (ou + 2 * (quick(2,base) - 1) % mod) % mod) % mod * quick(2,base) % mod * inv2 % mod;
ou = (ou + 2 * (quick(2,base)) % mod) % mod;
}
else{
shou[base] = ji;
sum[base] = (ji + (ji + 2 * (quick(2,base) - 1) % mod) % mod) % mod * quick(2,base) % mod * inv2 % mod;
ji = (ji + 2 * (quick(2,base)) % mod) % mod;
}
base++;
}while(rr > 0);
// for(int i = 0;i <= base;++i) printf("%lld\n",(long long)(sum[i]));
long long ans = ((work(R) - work(L - 1) + mod) % mod + mod) % mod;
printf("%lld\n",(long long)ans);
return 0;
}

D

化式子可以发现,只和\(a_i-b_i\)的值有关

然后就快乐排序算贡献

#include<cstdio>
#include<iostream>
#include<queue>
#include<algorithm>
#include<cstring>
#include<cctype>
#include<vector>
#include<ctime>
#include<cmath>
#define LL long long
#define pii pair<int,int>
#define mk make_pair
#define fi first
#define se second
using namespace std;
const LL mod = 1e9 + 7;
inline LL read(){
LL v = 0,c = 1;char ch = getchar();
while(!isdigit(ch)){
if(ch == '-') c = -1;
ch = getchar();
}
while(isdigit(ch)){
v = v * 10 + ch - 48;
ch = getchar();
}
return v * c;
}
LL L,R;
LL sum[129];
LL shou[129];
inline LL quick(LL x,LL y){
LL res = 1;
while(y){
if(y & 1) res = res * x % mod;
y >>= 1;
x = x * x % mod;
}
return res;
}
LL inv2 = quick(2,mod - 2);
inline LL work(LL x){
if(x == 0) return 0;
LL cnt = 0;
LL gg = 0;
LL ans = 0;
while(gg + (1ll << cnt) <= x){
ans = (ans + sum[cnt]) % mod;
gg += (1ll << cnt);
cnt++;
}
if(gg != x){
LL rest = (x - gg) % mod;
LL rail = (shou[cnt] + (rest - 1) * 2 % mod) % mod;
ans = (ans + (shou[cnt] + rail) % mod * rest % mod * inv2 % mod) % mod;
}
return ans;
}
int main(){
L = read(),R = read();
LL now = 0;
LL base = 0;
LL ji = 1;
LL ou = 2;
long long rr = R;
do{
rr -= (1ll << base);
// printf("%lld\n",rr);
if(base & 1){
shou[base] = ou;
sum[base] = (ou + (ou + 2 * (quick(2,base) - 1) % mod) % mod) % mod * quick(2,base) % mod * inv2 % mod;
ou = (ou + 2 * (quick(2,base)) % mod) % mod;
}
else{
shou[base] = ji;
sum[base] = (ji + (ji + 2 * (quick(2,base) - 1) % mod) % mod) % mod * quick(2,base) % mod * inv2 % mod;
ji = (ji + 2 * (quick(2,base)) % mod) % mod;
}
base++;
}while(rr > 0);
// for(int i = 0;i <= base;++i) printf("%lld\n",(long long)(sum[i]));
long long ans = ((work(R) - work(L - 1) + mod) % mod + mod) % mod;
printf("%lld\n",(long long)ans);
return 0;
}

E

首先一个小\(trick\)

树上的连通块数 = 点数 - 边数(本题是链也)

所以答案变成了点数之和减去边数之和

对于一个点\(i\),他的贡献应该是

\[a_i*(n - a_i + 1)
\]

就是左端点和右端点的取值都要合法

一条边存在仅当他链接的两个点都存在

\[min(a_i,a_{i + 1}) * (n - max(a_i,a_{i + 1}) + 1)
\]

所以把这些东西算一算就好了

#include<cstdio>
#include<iostream>
#include<queue>
#include<algorithm>
#include<cstring>
#include<cctype>
#include<vector>
#include<ctime>
#include<cmath>
#define LL long long
#define pii pair<int,int>
#define mk make_pair
#define fi first
#define se second
using namespace std;
const int N = 1e5 + 3;
int a[N];
int n;
inline int read(){
int v = 0,c = 1;char ch = getchar();
while(!isdigit(ch)){
if(ch == '-') c = -1;
ch = getchar();
}
while(isdigit(ch)){
v = v * 10 + ch - 48;
ch = getchar();
}
return v * c;
}
int main(){
LL ans = 0;
n = read();
for(int i = 1;i <= n;++i) a[i] = read();
for(int i = 1;i <= n;++i) ans += 1ll * a[i] * (n - a[i] + 1);
for(int i = 1;i < n;++i) ans -= 1ll * min(a[i],a[i + 1]) * (n - max(a[i],a[i + 1]) + 1);
cout << ans;
return 0;
}

F

见这一篇

CF1151div2(Round 553)的更多相关文章

  1. CodeForces Round #553 Div2

    A. Maxim and Biology 代码: #include <bits/stdc++.h> using namespace std; int N; string s; int mi ...

  2. Codeforces Round #553 (Div. 2)

    传送门 A. Maxim and Biology 题意: 给出一个串s,问最少需要多少步操作使得串s包含"ACTG"这个子串,输出最少操作次数: 题解: 枚举每个位置 i,求出将 ...

  3. Codeforces Round #553 (Div. 2) D题

    题目网址:http://codeforces.com/contest/1151/problem/D 题目大意:给出n组数对,(ai , bi),调整这n组数对的位置,最小化 ∑(ai*( i -1)+ ...

  4. Codeforces Round #553 (Div. 2) C题

    题目网址:http://codeforces.com/contest/1151/problem/C 题目大意:给定奇数集和偶数集,现构造一个数组,先取奇数集中一个元素1,再取偶数集二个元素2,4,再取 ...

  5. Codeforces Round #553 (Div. 2) B题

    题目网址:http://codeforces.com/contest/1151/problem/B 题目大意:给定一个n*m的矩阵,问是否可以从每一行中选择一个数,使得这n个数异或大于0,如果可以还要 ...

  6. Codeforces Round #553 (Div. 2) A题

    题目网址:http://codeforces.com/contest/1151/problem/A 题目大意:给定一个由大写字母构成的字符串和它的长度,有这样的操作,使任意一个字母变成与其相邻的字母, ...

  7. Codeforces Round #553 (Div. 2) C. Problem for Nazar 数学

    题意:从奇数列 1 3 5 7 9 ....  偶数列2 4 6 8 10...分别轮流取 1 2 4 ....2^n 个数构成新数列 求新数列的区间和 (就一次询问) 思路:首先单次区间和就是一个简 ...

  8. Codeforces Round #553 (Div. 2) D. Stas and the Queue at the Buffet 贪心+公式转化

    题意 给出n个pair (a,b) 把它放在线性序列上 1--n 上 使得  sum(a*(j-1)+b*(n-j))  最小 思路 :对式子进行合并 同类项 有:    j*(a-b)+  (-a+ ...

  9. Codeforces Round #553 (Div. 2)B. Dima and a Bad XOR 思维构造+异或警告

    题意: 给出一个矩阵n(<=500)*m(<=500)每一行任选一个数 异或在一起 求一个 异或在一起不为0 的每行的取值列号 思路: 异或的性质  交换律 x1^x2^x3==x3^x2 ...

随机推荐

  1. PHPCMS快速建站系列之后台内容自定义修改

    一.后台登录页面 背景图:\statics\images\admin_img 中的 login_bg.jpg 底部版权信息:\phpcms\languages\en 中的 system.lang.ph ...

  2. More Effective C++: 06杂项讨论

    32:在未来时态下发展程序 世事永远在变,好的软件对于变化有良好的适应能力:可以容纳新的性质,可以移植到新的平台,可以适应新的需求,可以掌握新的输入.所谓在未来时态下设计程序,就是接受“事情总会改变” ...

  3. POJ 1679The Unique MST

    Description Given a connected undirected graph, tell if its minimum spanning tree is unique. Definit ...

  4. mariadb配置文件优化参数

    mariadb数据库优化需要根据自己业务需求以及根据硬件配置来进行参数优化,下面是一些关于mariadb数据库参数优化的配置文件. 1 如下为128G内存32线程处理器的mariadb配置参数优化: ...

  5. map的三种遍历方法!

    map的三种遍历方法!   集合的一个很重要的操作---遍历,学习了三种遍历方法,三种方法各有优缺点~~ /* * To change this template, choose Tools | Te ...

  6. [java]struts2 模型驱动 2016-05-01 21:40 702人阅读 评论(19) 收藏

    一开始敲网上商城的时候,对于数据的传递方式我是很惊艳了一把的,感觉特别高大上,就感觉,竟然不用像.net一样取谁的值,给谁赋值这样,只要需要用的时候,简单的get一下就ok了,简直高大上啊. 然后发现 ...

  7. sql —— top

    用于规定要返回的记录的数目 原表: 我们如果只想看前三个学生信息的话:

  8. TextView.setTextColor(int); 括号里那个颜色int值的理解

    原本以为是R.id里的东西,后来发现不是 http://dianhua1990627.blog.163.com/blog/static/2755558820132262150387/

  9. 【批量添加】-拼接sql字符串 标签: 批量添加 2015-12-13 17:49 2070人阅读 评论(33)

    现在做的一个项目需要用到批量添加,但是封装的底层没有这个方法,所以自食其力,自己来写.我们用的是拼接sql字符串的方法来实现功能. 具体实现流程:首先将需要的数据存储到实体的list中,然后将这个li ...

  10. Java练习 SDUT-2272_Time

    Time Time Limit: 1000 ms Memory Limit: 65536 KiB Problem Description Digital clock use 4 digits to e ...