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. poj 2184 01背包变形【背包dp】

    POJ 2184 Cow Exhibition Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 14657   Accepte ...

  2. qt .pro文件和cmakelists.txt配置第三方库

    .pro文件引用第三方库文件和头文件路径 1.库文件(LIBS添加的是共享库文件,-L添加目录,-l指定共享库名称) LIBS += -L/usr/local/lib -lmath LIBS的使用就是 ...

  3. 《mysql必知必会》4笔记(存储过程、游标、触发器、事务、全球化本地化、权限、数据库维护、性能)

    二十三:使用存储过程: 1:mysql 5添加了对存储过程的支持.很多时候,一个完整的操作需要多条语句才能完成.存储过程简单来说,就是为以后的使用而保存的一条或多条mysql语句的集合,可将其视为批文 ...

  4. 【BootStrap】--具有增删改查功能的表格Demo

    [BootStrap]--具有增删改查功能的表格Demo 目录(?)[+] 前言 版本一 样式 代码 版本二 样式 代码 版本三 样式 代码 总结 前言 bootstrap的表格样式,有类似EasyU ...

  5. mybatis多排序问题

    在很多业务场景中,会有多排序问题,mybatis支持多排序,写法如下: ORDER BY contract.contractCount DESC, reward.rewardTotal DESC, n ...

  6. Gym - 101480D_Digit Division

    题意:输入n,m,将n分段,每一段都可以被m整除,有多少种方法. 题解:找到n最多可以分成多少段,1段1中分法,2段2中分法,3段4种分法--计算可知若有x段则2^x-1种分法. 注意:如果n无法被m ...

  7. LeetCode81 Search in Rotated Sorted Array II

    题目: Follow up for "Search in Rotated Sorted Array":What if duplicates are allowed? Would t ...

  8. laravel 5 自定义全局函数,怎么弄呢?

    在app/Helpers/(目录可以自己随便来) 下新建一个文件 functions.php 在functions.php 中加入这个方法 然后在 bootstrap/autoload.php 中添加 ...

  9. 基于LIVE555的RTSP QoS实现

    如何从OnDemandServerMediaSubsession类以及继承类对象中获取RTCP信息(句柄) OnDemandServerMediaSubsession.cpp void StreamS ...

  10. hdu 1217 Arbitrage(佛洛依德)

    Arbitrage Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Total S ...