Codeforces Round #513-ABCD
ABC现场做出,涨了八十几分吧。D有点思路不知道怎么实现,赛后看题解发现巨简单,想得太复杂了。蓝瘦。
A----http://codeforces.com/contest/1060/problem/A
题意:给定n位数,问能组成多少电话号码。电话号码是一个以8位开头的11位数
思路:统计一下8的个数,计算一下n/11的个数,两者取较小值即为答案
#include <bits/stdc++.h>
#include<iostream>
#include<cmath>
#include<algorithm>
#include<stdio.h>
#include<cstring>
#include<map> #define inf 0x3f3f3f3f
using namespace std;
typedef long long int LL; int n;
const int maxn = ;
int dig[]; int main()
{
while(scanf("%d", &n) != EOF){
char str[maxn];
scanf("%s", str);
memset(dig, , sizeof(dig));
int cnt = ;
for(int i = ; i < n; i++){
dig[str[i] - '']++;
cnt++;
} int ans = min(dig[], cnt / );
cout<<ans<<endl;
}
return ;
}
B---http://codeforces.com/contest/1060/problem/B
题意:给定一个n,要求两个数 a+b=n并且a的各数位之和和b的各数位之和相加是最大的,输出这个和
思路:有一个数一定是比n少一位的,全由9构成的数。
#include <bits/stdc++.h>
#include<iostream>
#include<cmath>
#include<algorithm>
#include<stdio.h>
#include<cstring>
#include<map> #define inf 0x3f3f3f3f
using namespace std;
typedef long long int LL; LL n; int main()
{
while(scanf("%I64d", &n) != EOF){
int dig = ;
LL tmp = n;
while(tmp){
tmp /= ;
dig++;
} dig--;
int ans = dig * ;
tmp = n;
LL ten = ;
while(dig){
tmp -= ten * ;
ten *= ;
dig--;
}
while(tmp){
ans += tmp % ;
tmp /=;
}
printf("%d\n", ans);
}
return ;
}
C---http://codeforces.com/contest/1060/problem/C
题意:给定两个数组a和b,矩阵c(i,j) = ai * bj,求矩阵c的一个子矩阵使得子矩阵中所有元素和小于x,并且要让这个子矩阵的元素个数尽可能多
思路:c是不需要算出来的。找c的一个子矩阵相当于分别找a和b中连续的一段区间。
首先预处理出a和b中,连续的长度为i的区间之和最小的。asum[i]即为a数组中,连续的长度为i的总和最小的区间
因为要让元素个数尽可能多,那么就应该要找和最小值
然后分别枚举子矩阵的行数和列数,找到和小于x且元素个数最多的
#include <bits/stdc++.h>
#include<iostream>
#include<cmath>
#include<algorithm>
#include<stdio.h>
#include<cstring>
#include<map> #define inf 0x3f3f3f3f
using namespace std;
typedef long long int LL; int n, m;
const int maxn = ;
LL a[maxn], b[maxn], x;
LL suma[maxn], sumb[maxn];
LL asum[maxn], bsum[maxn]; int main()
{
while(scanf("%d%d", &n, &m) != EOF){
memset(suma, , sizeof(suma));
memset(sumb, , sizeof(sumb));
for(int i = ; i <= n; i++){
scanf("%I64d", &a[i]);
suma[i] = suma[i - ] + a[i];
}
for(int i = ; i <= m; i++){
scanf("%I64d", &b[i]);
sumb[i] = sumb[i - ] + b[i];
}
scanf("%I64d", &x); memset(asum, inf, sizeof(asum));
memset(bsum, inf, sizeof(bsum));
for(int i = ; i <= n; i++){
for(int pos = i; pos <= n; pos++){
asum[i] = min(suma[pos] - suma[pos - i], asum[i]);
}
}
for(int i = ; i <= m; i++){
for(int pos = i; pos <= m; pos++){
bsum[i] = min(sumb[pos] - sumb[pos - i], bsum[i]);
}
} LL ans = ;
for(int i = n; i >= ; i--){
for(int j = m; j >= ; j--){
if(bsum[j] * asum[i] <= x){
if(i * j > ans){
ans = i * j;
}
}
}
} printf("%I64d\n", ans);
}
return ;
}
D---http://codeforces.com/contest/1060/problem/D
题意:有n个人坐成一圈 每个人都要求他的左边至少有a[i]个空位,右边有b[i]个空位。问要满足所有人的要求至少需要多少凳子。
思路:
现场的思路是所有人和空位之和。每次都找到左边空位最大的那个人,和右边空位最大的那个进行合并,总数就减去。合并之后相当于形成一个新的人。但是一时想不出来我形成新的人之后要怎么继续维护,难道每次都排序,肯定是不够的。
其实,合并并没有影响左边的数组和右边的数组。合并之后的左边和右边原来就在数组之中。
所以只需要先对a和b数组分别排序,每次取出a和b中的最大值。答案加上这两个最大之中的较大。最后答案加上n就行了。
#include <bits/stdc++.h>
#include<iostream>
#include<cmath>
#include<algorithm>
#include<stdio.h>
#include<cstring>
#include<map> #define inf 0x3f3f3f3f
using namespace std;
typedef long long LL; int n;
const int maxn = 1e5 + ;
int a[maxn], b[maxn]; int main()
{
while(scanf("%d", &n) != EOF){
for(int i = ; i < n; i++){
scanf("%d%d", &a[i], &b[i]);
}
sort(a, a + n);
sort(b, b + n); LL ans = n;
for(int i = ; i < n; i++){
ans += max(a[i], b[i]);
}
printf("%I64d\n", ans);
}
return ;
}
Codeforces Round #513-ABCD的更多相关文章
- Codeforces Round #513 游记
Codeforces Round #513 游记 A - Phone Numbers 题目大意: 电话号码是8开头的\(1\)位数字.告诉你\(n(n\le100)\)个数字,每个数字至多使用一次.问 ...
- Codeforces Round #513 总结
首次正式的$Codeforces$比赛啊,虽然滚粗了,然而终于有$rating$了…… #A Phone Numbers 签到题,然而我第一次写挂了(因为把11看成8了……) 只需要判断一下有多少个 ...
- Codeforces Round #513 by Barcelona Bootcamp C. Maximum Subrectangle(双指针+思维)
https://codeforces.com/contest/1060/problem/C 题意 给两个数组,a数组有n个元素,b数组有m个元素,两个数组元素互相相乘形成n*m的矩阵,找一个子矩阵,元 ...
- Codeforces Round #513解题报告(A~E)By cellur925
我是比赛地址 A:Phone Numbers $Description$:给你一串数字,问你能组成多少开头为8的11位电话号码. $Sol$:统计8的数量,与$n$%11作比较. #include&l ...
- Codeforces Round #513 by Barcelona Bootcamp (rated, Div. 1 + Div. 2) C D
C - Maximum Subrectangle 因为是两个数组相乘的到的 矩阵所以 a(i ->j)*b(x->y) 的面积 就是 a(i ->j) 的和乘与b(x-> ...
- Codeforces Round #513 by Barcelona Bootcamp
A. Phone Numbers 签. #include <bits/stdc++.h> using namespace std; #define N 110 char s[N]; ], ...
- Codeforces Round #513
A. Phone Numbers 题意:给一些数字,每个电话号码以8开头,11位,求最多组成多少个号码,重复累加. #include <bits/stdc++.h> using names ...
- [Codeforces Round #513 by Barcelona Bootcamp (rated, Div. 1 + Div. 2) ](A~E)
A: 题目大意:给你一个数字串,每个数字只可以用一次,求最多可以组成多少个电话号码(可以相同),电话号码第一个数字为$8$,且长度为$11$ 题解:限制为$8$的个数和总长度,直接求 卡点:无 C++ ...
- Codeforces Round 513 (Div.1+Div.2)
比赛传送门 10月4号的比赛,因为各种原因(主要是懒),今天才写总结-- Div1+Div2,只做出两个题+迟到\(20min\),日常掉\(rating\)-- \(\rm{A.Phone\;Num ...
- Codeforces Round #513 (rated, Div. 1 + Div. 2)
前记 眼看他起高楼:眼看他宴宾客:眼看他楼坍了. 比赛历程 开考前一分钟还在慌里慌张地订正上午考试题目. “诶这个数位dp哪里见了鬼了???”瞥了眼时间,无奈而迅速地关去所有其他窗口,临时打了一个缺省 ...
随机推荐
- atitit.提升软件开发的生产力关健点-------大型开发工具最关健
atitit.提升软件开发的生产力关健点-------大型开发工具最关健 1. 可以创作出更好的工具遍历自己 1 2. 大型工具包括哪些方面 2 2.1. ide 2 2.2. dsl 2 2.3. ...
- linux下实现CPU使用率和内存使用率获取方法
想获取一下目标机运行时linux系统的硬件占用情况,写了这几个小程序,以后直接用了. 方法就是读取proc下的文件来获取了. cpu使用率: /proc/stat ,内存使用情况: /p ...
- gzexe加密 脚本
sh-4.1# vi GZEXE.sh sh-4.1# cat GZEXE.sh #!/bin/bash echo "gzexe加密实验!!!" >> Cgzexe.l ...
- ubuntu下刷新dns
也是一条命令就可以:sudo /etc/init.d/dns-clean start
- 数学 - Codeforces Round #319 (Div. 1)A. Vasya and Petya's Game
Vasya and Petya's Game Problem's Link Mean: 给定一个n,系统随机选定了一个数x,(1<=x<=n). 你可以询问系统x是否能被y整除,系统会回答 ...
- 【转】【C#】迭代器IEnumerable和IEnumerator
迭代器模式是设计模式中行为模式(behavioral pattern)的一个例子,他是一种简化对象间通讯的模式,也是一种非常容易理解和使用的模式.简单来说,迭代器模式使得你能够获取到序列中的所有元素而 ...
- (转)FS_S5PC100平台上Linux Camera驱动开发详解(二)
4-3 摄像头的初始化流程及v4l2子设备驱动 这个问题弄清楚了以后下面就来看获得Camera信息以后如何做后续的处理: 在fimc_init_global调用结束之后我们获得了OV9650的信息,之 ...
- 【BZOJ】1068: [SCOI2007]压缩(dp)
http://www.lydsy.com/JudgeOnline/problem.php?id=1068 发现如果只设一维的话无法转移 那么我们开第二维,发现对于前i个来说,如果确定了M在哪里,第i个 ...
- 【BZOJ】1621: [Usaco2008 Open]Roads Around The Farm分岔路口(dfs)
http://www.lydsy.com/JudgeOnline/problem.php?id=1621 这题用笔推一下就懂了的.... 当2|(n-k)时,才能分,否则不能分. 那么dfs即可.. ...
- Sublime Text 模版插件: SublimeTmpl
开发者的插件介绍页面:http://www.fantxi.com/blog/archives/sublime-template-engine-sublimetmpl/ 写了个sublime的模版插件, ...