A

温暖的签到

#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
int main(){LL n,m,k;scanf("%I64d%I64d%I64d",&n,&m,&k);if( min( m,k ) >= n ){printf("Yes");}else{printf("No");}return 0;
}

C

我们模仿KMP算法的思路,预处理子串。注意到a中相邻的两个长度为b的串的奇偶性的差异只与 子串每一位是否与前面那位 和新添加尾部的 和减少的首位 这三个元素有关。

#include <bits/stdc++.h>
using namespace std;
typedef int lint;
typedef long long LL;
int main(){string a,b;cin >> a>> b;lint len = b.length();lint flag = 0;for( lint i = 1;i < len;i++ ){if( b[i] != b[i-1] )flag^= 1;}lint flag2 = 0;for( lint i = 0;i < len;i++ ){if( a[i] != b[i] ) flag2^=1;}LL ans = 0;if( !flag2 ) ans++;lint len2 = a.length();for( lint i = 1;i+len <= len2;i++ ){flag2 ^= flag;if( a[i+len-1] != b[len-1] ){flag2 ^= 1;}if( a[i-1] != b[0] ){flag2 ^= 1;}if( !flag2 ) ans++;}cout << ans;return 0;
}

D

注意到上取整和下取整 对于总和的影响差值为1,所以我们不妨全部下取整,看加上几个1之后结果为0.

坑点:( double )floor( double ) 下取整

( double )ceil(double ) 上取整

STL真好用

#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
typedef int lint;
const lint maxn = 1e5 + 1;
double a[maxn],b[maxn],c[maxn];
int main(){lint n;double sum = 0;scanf("%d",&n);for( lint i = 1;i <= n;i++ ){scanf("%lf",&a[i]);b[i] = floor(a[i]);c[i] = ceil(a[i]);sum += b[i]-a[i];}for( lint i = 1;i <= n;i++ ){if( abs(sum - 0) > 1e-6 ){sum += c[i]-b[i];if( c[i] > 0 ) c[i] += 0.1;else c[i] -= 0.1;printf("%I64d\n",(LL)(c[i]));}else{if( c[i] > 0 ) c[i] += 0.1;else c[i] -= 0.1;printf("%I64d\n",(LL)(b[i]));}}return 0;
}

E

这题好有趣啊

我最开始的想法是将要求的矩形直接拆成一些矩形的面积并,但是发现这些整块的矩形的面积不好算。只有一些特定的矩形的面积才好算。比如面积的前缀。画个图就会发现,边长为 n * 2 ^ i( i >= 1 ) 或 边长为 m * 2 ^ i ( i >= 1 )  的前缀矩形是对称的,其中1的个数为面积的一半。有了这个结论,那么问题就转化为求任意一个前缀矩形的面积,经过上述的拆分,最后余下的矩形一定在边长为 2* n * 2 * m 的矩形之中。这就好求了,还需要注意此时余下的矩形是以1为左上角还是以0为左上角的矩形。

#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
typedef int lint;
const lint maxn = 2005;
lint a[maxn][maxn],sum[maxn][maxn];
vector<LL> ven,vem;
void prework( lint n,lint m ){for( lint i = 1;i <= n;i++ ){for( lint j = 1;j <= m;j++ ){sum[i][j] = sum[i-1][j] + sum[i][j-1]-sum[i-1][j-1];sum[i][j] += a[i][j];}}ven.push_back( n );for( ;n <= 1e9+1;n *= 2 ){ven.push_back( n );}vem.push_back( m );for( ;m <= 1e9+1;m*= 2 ){vem.push_back(m);}
}
LL solve( LL n,LL m,lint f ){if( !n || ! m ) return 0;lint p1 = upper_bound( ven.begin(),ven.end(),n ) - ven.begin();p1--;lint p2 = upper_bound( vem.begin(),vem.end(),m ) - vem.begin();p2--;if( p1 == -1&& p2 == -1 ){if( f ){return sum[n][m];}else return n*m - sum[n][m];}LL sum = 0;if( p1 >= 0 ){n -= ven[p1];sum += ven[p1]*m/2;return sum + solve( n,m,f^1 );}if( p2 >= 0 ){m -= vem[p2];sum += vem[p2]*n/2;return sum + solve( n,m,f^1 );}
}
int main(){lint n,m,q;scanf("%d%d%d",&n,&m,&q);for( lint i = 1;i <= n;i++ ){for( lint j = 1;j <= m;j++ ){scanf("%1d",&a[i][j]);a[i+n][j] = !a[i][j];a[i][j+m] = !a[i][j];a[i+n][j+m] = a[i][j];}}prework((LL)2*n,(LL)2*m);LL x1,x2,y1,y2;for( lint i = 1;i <= q;i++ ){scanf("%I64d%I64d%I64d%I64d",&x1,&y1,&x2,&y2);LL ans = solve( x2,y2,1 ) - solve( x2,y1-1,1 ) - solve( x1-1,y2,1 ) + solve( x1-1,y1-1,1 );printf("%I64d\n",ans);}return 0;
}

F.欧拉回路递归写法居然爆栈了。所以学到了非递归的写法。

注意到每个点最多删掉一半的边,我们新增加一个原点,将其与所有的奇度点相连接。然后跑一个欧拉回路得到一个边序列。我们把序列中下标为偶数的边删去。 一个点相邻的两边在序列中是连续的。所以每个点删掉的边数小于等于度数的一半。但是可能删掉的一半边中都是原来存在的。所以我们找到新加的边中度数为奇数的边来代替。

注意:欧拉回路的非递归写法会改变链式前向星的结构。

#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
typedef int lint;
typedef pair<lint,lint> pii;
const lint maxn = 2000001;
const lint maxm = 4000001;
lint tot,ver[maxm],he[maxn],ne[maxm],id[maxm];
pii edge[maxm];
void add( lint x,lint y,lint n ){ver[++tot] = y;ne[tot] = he[x];he[x] = tot;id[tot] = n;
}
vector<lint> ans;
lint vis[maxm],v[maxn],vis2[maxm],st[maxm],re[maxm],top;
void euler( lint x ){st[++top] = x;while( top>0 ){lint x = st[top];lint cure  = he[x];while( cure && vis[cure] ) cure = ne[cure];if( cure ){lint y = ver[cure];vis[cure] = vis[cure^1] = 1;st[++top] = y;re[top] = id[cure];he[x] = ne[cure];}else{if( top !=  1  )ans.push_back( re[top] );top--;}}
}
vector<lint> res;
lint du[maxm];
int main(){lint n,m;scanf("%d%d",&n,&m);tot = 1;for( lint x,y,i = 1;i <= m;i++ ){scanf("%d%d",&x,&y);add( x,y,i );add( y,x,i );du[x]++;du[y]++;edge[i].first = x;edge[i].second = y;}lint totm = m;for( lint i = 1;i <= n;i++ ){if( du[i]&1 ){add( 0,i,++totm );add( i,0,totm );}}int res = m;for (int i = 0; i <= n; i++) {ans.clear();euler(i);for (int j = 1; j < ans.size(); j += 2) {int now = ans[j];if(now > m) vis2[now] = 1;else {int tmp = ans[j - 1];if(tmp> m && vis2[tmp] == 0) {vis2[tmp] = 1;continue;}int Next = j + 1;if(j == ans.size()) Next = 0;tmp = ans[Next];if(tmp > m && vis2[tmp] == 0) {vis2[tmp] = 1;continue;}vis2[now] = 1;res--;}}}printf("%d\n", res );for( lint i = 1;i <= m;i++ ){if( vis2[i] ) continue;printf("%d %d\n", edge[i].first,edge[i].second );}return 0;
}

Codeforces Round #571 (Div. 2)相关推荐

  1. 南昌不翻车 Codeforces Round #571 (Div. 2) C,D

    http://codeforces.com/contest/1186 C:(挺好的思维题) 题目大意:给俩串,A和B,然后A的每一个B子串,有一个价值,就是和B不同的数目,然后让统计偶数的代价有多少个 ...

  2. Codeforces Round #506 (Div. 3)

    Codeforces Round #506 (Div. 3) 实习期间事不多,对div3 面向题解和数据编程了一波 A. Many Equal Substrings 题目链接 A题就是找后缀和前缀重合 ...

  3. Codeforces Round #563 (Div. 2)/CF1174

    Codeforces Round #563 (Div. 2)/CF1174 CF1174A Ehab Fails to Be Thanos 其实就是要\(\sum\limits_{i=1}^n a_i ...

  4. 构造 Codeforces Round #302 (Div. 2) B Sea and Islands

    题目传送门 1 /* 2 题意:在n^n的海洋里是否有k块陆地 3 构造算法:按奇偶性来判断,k小于等于所有点数的一半,交叉输出L/S 4 输出完k个L后,之后全部输出S:) 5 5 10 的例子可以 ...

  5. Codeforces Round #696 (Div. 2) (A ~ E)超高质量题解(每日训练 Day.16 )

    整理的算法模板合集: ACM模板 点我看算法全家桶系列!!! 实际上是一个全新的精炼模板整合计划 Codeforces Round #696 (Div. 2) (A ~ E)超高质量题解 比赛链接:h ...

  6. Codeforces Round #712 Div.2(A ~ F) 超高质量题解(每日训练 Day.15 )

    整理的算法模板合集: ACM模板 点我看算法全家桶系列!!! 实际上是一个全新的精炼模板整合计划 Codeforces Round #712 Div.2(A ~ F) 题解 比赛链接:https:// ...

  7. Codeforces Round #701 (Div. 2) A ~ F ,6题全,超高质量良心题解【每日亿题】2021/2/13

    整理的算法模板合集: ACM模板 点我看算法全家桶系列!!! 实际上是一个全新的精炼模板整合计划 目录 A - Add and Divide B - Replace and Keep Sorted C ...

  8. Codeforces Round #700 (Div. 2) D2 Painting the Array II(最通俗易懂的贪心策略讲解)看不懂来打我 ~

    整理的算法模板合集: ACM模板 点我看算法全家桶系列!!! 实际上是一个全新的精炼模板整合计划 整场比赛的A ~ E 6题全,全部题目超高质量题解链接: Codeforces Round #700 ...

  9. Codeforces Round #699 (Div. 2) F - AB Tree(贪心、树上DP)超级清晰,良心题解,看不懂来打我 ~

    整理的算法模板合集: ACM模板 点我看算法全家桶系列!!! 实际上是一个全新的精炼模板整合计划 Codeforces Round #699 (Div. 2) F - AB Tree Problem ...

最新文章

  1. Python 文件 close() 方法
  2. 网站微信登录授权 ASP.NET
  3. java基础提升篇:synchronized同步块和volatile同步变量
  4. Mysql 主从数据库同步详解
  5. sql server总结二
  6. Homography
  7. python增加一列数据_python数据怎么添加列?
  8. python 每天执行一次_python 定时器每天就执行一次的实现代码
  9. 数学基础 —— 线性代数
  10. micropython开发idethonny_Thonny 3.0 首个稳定版发布,一个面向初学者的 Python IDE
  11. EntityFramework 4.1 如何加入项目
  12. Python3实现文件名排序
  13. SAP-PP后台配置(第二部分)
  14. PRML 回归的线性模型
  15. 我的她 —— 记我的 IBM R51
  16. jbox弹窗_jbox很好的弹出层 很好的弹出层 - 下载 - 搜珍网
  17. SAP MD04详解
  18. rep论文阅读2:ResRep_Lossless CNN Pruning via Decoupling Remembering and Forgetting
  19. Unity关于无法新建项目的可能解决办法
  20. 7-1 用格里高利公式求给定精度的PI值 (15分)

热门文章

  1. 全文搜索 full-text search
  2. 当程序员后,才突然明白的21件事……
  3. 来看一个费解而有趣的c++现象
  4. 计算机与网络应用封面,计算机二级考试真题-Word-小王-计算机与网络应用
  5. 《读者》的“卷首语” (二)
  6. 2019第十届蓝桥杯省赛总结
  7. Vue 使用 yarn 报错
  8. php相同数据合并单元格,jQuery_基于jQuery的合并表格中相同文本的相邻单元格的代码,ONE 已经生成的数据表格大致 - phpStudy...
  9. linux一次系统调用时间,Linux系统调用—时间和日期
  10. spring-boot 修改启动图标