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哪里见了鬼了???”瞥了眼时间,无奈而迅速地关去所有其他窗口,临时打了一个缺省 ...
随机推荐
- wechat talk
https://github.com/13770344697/nanjingzhongan https://github.com/fayuanliu/wxRobot https://github.co ...
- dbrd 8.4.6 源代码编译安装
---------------------------- 0.系统环境 ---------------------------- db01 192.168.50.10 /dev/sdb1 主节点 db ...
- $sanitize和$sce服务的使用方法
var app =angular.module(‘myApp‘,[‘ngSanitize‘]); app.controller(‘ctrl‘,function($scope,$sce){ $scope ...
- Ownerdrawn ComboBox
[ToolboxBitmap(typeof(ComboBox))] class ComboBoxEx : ComboBox { public ComboBoxEx() { this.DrawMode ...
- 每日英语:China Grapples With Genetically Modified Foods
A Chinese agricultural official's unsupported claims about the carcinogenic risks of consuming genet ...
- Spring Oauth2 with JWT Sample
https://www.javacodegeeks.com/2016/04/spring-oauth2-jwt-sample.html ******************************** ...
- oracle ORA-12545:因目标主机或对象不存在
解决方法: 1.首先从最基本的入手,这里打开计算机右击,选择管理 2. 找到里面的服务和应用程序,打开服务 3.找到: OracleOraDb11g_home1TNSListener OracleSe ...
- Unity3D学习(十):使用VideoPlayer在UI上播放视频
前言 每一款游戏往往启动的第一次都会播放CG动画之类的,Unity本身对于移动平台也提供了一个接口. Handheld.PlayFullScreenMovie("path") 过场 ...
- python操作word【简单封装】
#!/usr/bin/env python # -*- coding: utf-8 -*- import win32com.client import os #-------------------- ...
- PHP——0128练习相关1——window.open()
Window.open()方法参数详解 1, 最基本的弹出窗口代码 window.open('page.html'); 2, 经过设置后的弹出窗口 window.open('page.html ...