Codeforces Educational Round 5
通过数: 4
Standing: 196/4176
题目链接: http://codeforces.com/contest/616
A:
两个大数,可能有首0.
问哪个数大

#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <string>
#include <algorithm>
#include <iostream>
using namespace std;
const int MAXN = 1000000 + 6;
char s1[MAXN], s2[MAXN];
int main()
{while(scanf("%s%s", s1, s2) != EOF){int len1 = strlen(s1);int len2 = strlen(s2);int t1 = 0, t2 = 0;while(s1[t1] == '0')    t1++;while(s2[t2] == '0')    t2++;if(len1 - t1 > len2 - t2)   printf(">\n");else if(len1 - t1 < len2 - t2) printf("<\n");else{int flag = 0;for(int i = 0 ; i < len1 - t1 ; i++){if(s1[i + t1] > s2[i + t2]){flag = 1; break;}else if(s1[i + t1] < s2[i + t2]){flag = -1; break;}}if(flag == 1)   printf(">\n");else if(flag == -1) printf("<\n");else printf("=\n");}}return 0;
}

B:
题目写的很复杂,剥壳以后就是每一行的最小值的最大值。

#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <string>
#include <algorithm>
#include <iostream>
using namespace std;
#define inf (1000000007)
const int MAXN = 100 + 5;
int c[MAXN][MAXN];
int mmax[MAXN];
int main()
{int n, m;while(scanf("%d%d", &n, &m) != EOF){int ans = 0;for(int i = 1 ; i <= n ; i++){mmax[i] = inf;for(int j = 1 ; j <= m ; j++)   scanf("%d", &c[i][j]), mmax[i] = min(mmax[i], c[i][j]);ans = max(ans, mmax[i]);}printf("%d\n", ans);}return 0;
}

C:
一个矩阵上,一些点空格一些点有障碍。
问对于每个障碍,如果障碍不见了,它与原先的图能够成的连通子块里面有多少个点。
把原图做一个连通分量标号,两边dfs就可以。第一遍计数,第二遍标号。
忘记输出数要%10 WA了两发

#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <string>
#include <algorithm>
#include <iostream>
using namespace std;
const int MAXN = 1000 + 5;
char str[MAXN][MAXN];
int vis[MAXN][MAXN];
int cnt;
int id[MAXN][MAXN], id_cnt;
int num[MAXN * MAXN];
int n, m;
int dx[] = {-1, 0, 1, 0};
int dy[] = {0, 1, 0, -1};
bool valid(int x, int y)
{if(x < 1 || x > n)  return false;if(y < 1 || y > m)  return false;return true;
}
void dfs1(int x, int y)
{vis[x][y] = 1;cnt++;for(int i = 0 ; i < 4 ; i++){int tx = dx[i] + x;int ty = dy[i] + y;if(valid(tx, ty) && vis[tx][ty] == 0 && str[tx][ty] == '.'){dfs1(tx, ty);}}
}
void dfs2(int x, int y)
{vis[x][y] = 2;id[x][y] = id_cnt;for(int i = 0 ; i < 4 ; i++){int tx = dx[i] + x;int ty = dy[i] + y;if(valid(tx, ty) && vis[tx][ty] < 2 && str[tx][ty] == '.'){dfs2(tx, ty);}}
}
int a[5];
int main()
{while(scanf("%d%d", &n, &m) != EOF){for(int i = 1 ; i <= n ; i++) scanf("%s", str[i] + 1);id_cnt = 0;memset(vis, 0, sizeof(vis));for(int i = 1 ; i <= n ; i++){for(int j = 1 ; j <= m ; j++){if(vis[i][j] || str[i][j] == '*')   continue;cnt = 0;dfs1(i, j);num[++id_cnt] = cnt;dfs2(i, j);}}for(int i = 1 ; i <= n ; i++){for(int j = 1 ; j <= m ; j++){if(str[i][j] == '.') printf(".");else{int tcnt = 0;a[0] = 0;for(int k = 0 ; k < 4 ; k++){int tx = dx[k] + i;int ty = dy[k] + j;if(valid(tx, ty) && str[tx][ty] == '.')a[tcnt++] = id[tx][ty];}if(tcnt == 0){printf("1");continue;}sort(a, a + tcnt);int ans = num[a[0]];
//                    if(i == n && j == m) printf("%d\n", ans);for(int k = 1 ; k < tcnt ; k++){if(a[k] != a[k - 1]) ans += num[a[k]];
//                        if(i == n && j == m) printf("%d\n", ans);}printf("%d", (ans+1) % 10);}}printf("\n");}}return 0;
}

D:
问最长的序列,里面不同的数不超过k个。
开头尾指针O(2*n)就可以,不明白为什么不是第三题

 #include <cstdio>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <string>
#include <algorithm>
#include <iostream>
using namespace std;
const int MAXN = 1e6 + 5;
int vis[MAXN], a[MAXN];
int main()
{int n, k;while(scanf("%d%d", &n, &k) != EOF){memset(vis, 0, sizeof(vis));int cnt = 0;int pre = 1;int ans = 1, x, y;x = y = 1;for(int i = 1 ; i <= n ; i++){scanf("%d", &a[i]);if(vis[a[i]] == 0) cnt++;vis[a[i]]++;while(cnt > k && pre <= i){vis[a[pre]]--;if(vis[a[pre]] == 0) cnt--;pre++;}if(ans < i - pre + 1) ans = i - pre + 1, x = pre, y = i;}printf("%d %d\n", x, y);}return 0;
}

E:
题意是问n%1 + n%2 + .. + n%m等于多少(n,m <= 1e13)
打表找规律,没有规律。想到了大概能转换成ans = n*m - n/i*i的形式,n/i对于一段区间是一个定数所以可以做。但是发现n/i也可能很大,然后就跪了。
标解。发现对于n/i*i,要么n/i <= sqrt(n),要么i <= sqrt(n)。故原值分为两段。I

#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <string>
#include <algorithm>
#include <iostream>
using namespace std;
#define LL long long
#define mod (1000000007)
LL ppow(LL a, int x)
{a %= mod;LL ans = 1;for(int i = x ; i ; i >>= 1){if(i & 1) ans = (ans * a) % mod;a = (a * a) % mod;}return ans;
}
LL mul(LL u, LL v)
{return (u % mod) * (v % mod) % mod;
}
LL rev(LL a){return ppow(a, mod - 2);}
LL cal(LL l, LL r){return mul(mul((l + r), (r - l + 1)), rev(2));}
LL divise(LL u){return (u % mod + mod) % mod;}
int main()
{LL n, m;while(scanf("%I64d%I64d", &n, &m) != EOF){LL sn = sqrt(1.0 * n);
//        printf("sn = %I64d\n", sn);LL ans = 0;for(LL i = 1 ; i <= min(sn, m) ; i++){ans = (ans + mul(n / i, i)) % mod;}
//        printf("ans1 = %I64d\n", ans);
//        LL ans2 = 0;
//        printf("sn = %I64d\n", sn);int f = 1;LL i = sn;
//        printf("second\n");
//        printf("%I64d\n", n / (i + 1) + 1);while(n / (i + 1) + 1 <= sn){i--;
//            printf("i = %I64d", i);
//            system("pause");}
//        printf("second\n");for(; i >= 1 ; i--){int flag = 0;LL r = floor(1.0 * n / i);if(r >= m) r = m, flag = 1;LL l = floor(1.0 * n / (i + 1)) + 1;if(l > m) break;
//            if(f){
//                printf("l = %I64d, r = %I64d\n", l, r);
//                f = 0;
//            }
//            printf("i = %I64d, l = %I64d, r = %I64d, ans2 = %I64d\n", i, l, r, ans2);ans = (ans + mul(i, cal(l, r))) % mod;
//            if(flag){
//                printf("i = %I64d, l = %I64d, r = %I64d\n", i, l, r);
//            }if(flag)    break;}printf("%I64d\n", divise(mul(n, m) - ans));}return 0;
}
改进版
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <string>
#include <algorithm>
#include <iostream>
using namespace std;
#define LL long long
#define mod (1000000007)
#define MAXN (2000000)
LL ppow(LL a, int x)
{a %= mod;LL ans = 1;for(int i = x ; i ; i >>= 1){if(i & 1) ans = (ans * a) % mod;a = (a * a) % mod;}return ans;
}
LL mul(LL u, LL v)
{return (u % mod) * (v % mod) % mod;
}
LL rev(LL a){return ppow(a, mod - 2);}
LL cal(LL l, LL r){return mul(mul((l + r), (r - l + 1)), rev(2));}
LL divise(LL u){return (u % mod + mod) % mod;}
int main()
{LL n, m;while(scanf("%I64d%I64d", &n, &m) != EOF){LL ans = 0;LL rec = m + 1;for(LL i = 1 ; i < MAXN ; i++){LL l = n / (i + 1) + 1;LL r = min(n / i, m);if(l > r) continue;
//            printf("l = %I64d, r = %I64d\n", l, r);rec = min(l, rec);ans = (ans + mul(i, cal(l, r))) % mod;}
//        printf("ans = %I64d\n", ans);
//        printf("rec = %I64d\n", rec);for(LL i = 1 ; i < rec ; i++){ans = (ans + n - n % i) % mod;}printf("%I64d\n", divise(mul(n, m) - ans));}return 0;
}

Codeforces Educational Round 5相关推荐

  1. Codeforces Educational round 58

    Ediv2 58 随手AK.jpg D 裸的虚树,在这里就不写了 E 傻逼贪心?这个题过的比$B$都多.jpg #include <cstdio> #include <algorit ...

  2. Codeforces Educational Round#21 F(808F) Solution:网络流(最小割)

    题意:给出一组卡牌(100张),卡牌有三个属性值:power,c,level,其中c和level是用来限制的,power是目标值. 具体的限制规则是:只有level小于等于玩家的playerlevel ...

  3. Codeforces Educational Round #42

    终于上紫了qaq 算是省选前的一个好消息了吧qaq 值得纪念.4.10-4.11 CF962A Equator(模拟) #include <cstdio> #include <cst ...

  4. [Educational Round 5][Codeforces 616F. Expensive Strings]

    这题调得我心疲力竭...Educational Round 5就过一段时间再发了_(:з」∠)_ 先后找了三份AC代码对拍,结果有两份都会在某些数据上出点问题...这场的数据有点水啊_(:з」∠)_[ ...

  5. Codeforces Global Round 1 晕阙记

    Codeforces Global Round 1 晕阙记 我做这场比赛的时候晕得要死.做这三道题做太久了,rating涨不起来啊! A 如果愿意的话你可以看做是膜2意义下的运算,写快速幂等各种膜运算 ...

  6. Codeforces Beta Round #17 D. Notepad (数论 + 广义欧拉定理降幂)

    Codeforces Beta Round #17 题目链接:点击我打开题目链接 大概题意: 给你 \(b\),\(n\),\(c\). 让你求:\((b)^{n-1}*(b-1)\%c\). \(2 ...

  7. 【Codeforces】Round #488 (Div. 2) 总结

    [Codeforces]Round #488 (Div. 2) 总结 比较僵硬的一场,还是手速不够,但是作为正式成为竞赛生的第一场比赛还是比较圆满的,起码没有FST,A掉ABCD,总排82,怒涨rat ...

  8. Codeforces Global Round 3

    Codeforces Global Round 3 A. Another One Bites The Dust 有若干个a,有若干个b,有若干个ab.你现在要把这些串拼成一个串,使得任意两个相邻的位置 ...

  9. codeforces educational round110 e

    codeforces educational round110 e 给一颗初始只有根节点0的树,规定一个节点有数量aia_iai​,单位价格为cic_ici​的矿物.q个操作,一是往某一个节点下增加一 ...

最新文章

  1. 为什么说 Serverless 引领云的下一个十年?
  2. DHCP和DHCP中继功能与配置
  3. dfs递归实现组合型枚举
  4. 如何理解封装java_理解 Java 的三大特性之封装
  5. 问题十八:怎么对ray tracing图形进行消锯齿
  6. 计算机课题立项申报书范文,专项课题立项申报书模板.doc
  7. 经典网络结构 (五):ResNet (残差网络)
  8. MRPT笔记——MRPT在VS2013中的配置
  9. dnf时装预览怎么打开_dnf时装预览怎么打开_dnf怎么查找各职业时装代码
  10. 另辟蹊径 直取通州的“墨迹天气”APP应用的成功故事
  11. html制作学生信息表静态网页,实验一静态网页制作报告.doc
  12. zotero+坚果云+PDF Expert实现ipad与windows文献阅读同步
  13. 自然语言处理从零到入门 自然语言理解NLU
  14. php使用ElasticSearch
  15. Swift — UIKit 之(8)—— 持久层|用户偏好设置
  16. 基于C#winform的学生信息管理与成绩评价系统
  17. 成立 4 年估值 20 亿美金,这家国货美妆找到了新的人口红利
  18. 11-15ov9281双摄-应用运行命令
  19. 大数据中间件跨系统整合数据,打通数据鸿沟
  20. 计算机格式化磁盘6,装机必学:硬盘分区、格式化通用方法大全

热门文章

  1. pip install xxxx 报错 failed to create process解决方法
  2. 经典案例:找共同好友
  3. 江苏计算机事业单位考试内容和分值,江苏事业单位统考题型分值一览
  4. 运行github上的项目的教程
  5. 展馆室内定位导航系统功能解读
  6. centOS下安装php7及扩展
  7. jquery冲突的关键字nodeName、nodeValue和nodeType!
  8. C#实战005:Excel操作-引入Microsoft.Office.Interop.Excel组件
  9. linux arpspoof命令,Arpspoof的具体使用
  10. 2022神经渲染的进展综述