Codeforces Round #427 (Div. 2)
B. The number on the board
题意:
有一个数字,它的每个数位上的数字的和不小于等于k。现在他改变了若干位,变成了一个新的数n,问现在的数和原来的数最多有多少位不同。
思路:
如果现在的数字各位数字之和大于等于k,那么它就可能没有被改变。
反之,那么每个数的最大改变量就是9减去这个数,于是把9减去每个数得到的结果从大到小排序,用k减去现在的数位和得到的结果记为kk,遍历一遍差量数组,用kk去减,知道kk小于0跳出。
代码:
#include <stdio.h>
#include <string.h>
#include <algorithm>
using namespace std; bool cmp(int a,int b)
{
return a > b;
} int b[]; int main()
{
long long k; scanf("%I64d",&k); char s[]; long long sum = ; scanf("%s",s); int len =strlen(s); for (int i = ;i < len;i++)
{
int t = s[i] - '';
b[i] = - t;
sum += t;
} if (sum >= k) printf("0\n");
else
{
sort(b,b+len,cmp); long long ans = k - sum; int num = ; for (int i = ;i < len;i++)
{
ans -= b[i]; num++; if (ans <= )
{
break;
}
} printf("%d\n",num);
} return ;
}
C. Star sky
题意:
在一个平面直角坐标系上,有闪亮的星星。每个星星的最大亮度为相同的c,每颗星星有不同的起始亮度si,从开始时刻起每一秒亮度加1,如果当前亮度为c,那么下一秒就是0.
一开始给出每个星星的坐标和初始亮度,之后给出若干个询问,给出此时的时刻,矩形的左下角的坐标和右上角的坐标,统计在这个矩形内的所有的星星的亮度的总和(包括边界)。
思路:
一开始用暴力直接tle,遂在赛后看题解补题。前缀法,总的来说就是sum (a,b,c,d) = pre(c-1,b) - pre(a,y-1)-pre(c - 1,d - 1);
什么意思呢,pre(a,b)代表的是在(0,0)到(a,b)这个区间内的所有星星的总数(当然是分亮度的),看图
在每个询问的时候,统计0到c的亮度的星星在t时刻的亮度 (j + t) % (c + 1)
然后对亮度进行累加。(中间把j写成了tt,wa了无数次,还是要深入思考,彻底搞懂)
代码:
#include <stdio.h>
#include <string.h> int pre[][][]; int main()
{
int n,q,c; scanf("%d%d%d",&n,&q,&c); for (int i = ;i < n;i++)
{
int x,y,s; scanf("%d%d%d",&x,&y,&s); pre[x][y][s]++;
} for (int i = ;i <= ;i++)
for (int j = ;j <=;j++)
for (int k = ;k <= c;k++)
{
pre[i][j][k] += (pre[i-][j][k] + pre[i][j-][k] - pre[i-][j-][k]);
} for (int i = ;i < q;i++)
{
int t,x,y,a,b; scanf("%d%d%d%d%d",&t,&x,&y,&a,&b); int ans = ; for (int j = ;j <= c;j++)
{
int tt = (j+t) % (c + ); int tmp = pre[a][b][j] - pre[a][y-][j] - pre[x-][b][j] + pre[x-][y-][j]; ans += tmp * tt;
} printf("%d\n",ans);
} return ;
}
Codeforces Round #427 (Div. 2)的更多相关文章
- CodeForces 835C - Star sky | Codeforces Round #427 (Div. 2)
s <= c是最骚的,数组在那一维开了10,第八组样例直接爆了- - /* CodeForces 835C - Star sky [ 前缀和,容斥 ] | Codeforces Round #4 ...
- CodeForces 835D - Palindromic characteristics | Codeforces Round #427 (Div. 2)
证明在Tutorial的评论版里 /* CodeForces 835D - Palindromic characteristics [ 分析,DP ] | Codeforces Round #427 ...
- Codeforces Round #427 (Div. 2) Problem D Palindromic characteristics (Codeforces 835D) - 记忆化搜索
Palindromic characteristics of string s with length |s| is a sequence of |s| integers, where k-th nu ...
- Codeforces Round #427 (Div. 2) Problem C Star sky (Codeforces 835C) - 前缀和
The Cartesian coordinate system is set in the sky. There you can see n stars, the i-th has coordinat ...
- Codeforces Round #427 (Div. 2) Problem A Key races (Codeforces 835 A)
Two boys decided to compete in text typing on the site "Key races". During the competition ...
- Codeforces Round #427 (Div. 2) B. The number on the board
引子: A题过于简单导致不敢提交,拖拖拉拉10多分钟还是决定交,太冲动交错了CE一发,我就知道又要错过一次涨分的机会.... B题还是过了,根据题意目测数组大小开1e5,居然蒙对,感觉用vector更 ...
- Codeforces Round #427 (Div. 2)—A,B,C,D题
A. Key races 题目链接:http://codeforces.com/contest/835/problem/A 题目意思:两个比赛打字,每个人有两个参数v和t,v秒表示他打每个字需要多久时 ...
- Codeforces Round #427 (Div. 2)——ABCD
http://codeforces.com/contest/835 A.拼英语水平和手速的签到题 #include <bits/stdc++.h> using namespace std; ...
- 【Codeforces Round #427 (Div. 2) D】Palindromic characteristics
[Link]:http://codeforces.com/contest/835/problem/D [Description] 给你一个字符串; 让你在其中找到1..k阶的回文子串; 并统计它们的数 ...
- 【Codeforces Round #427 (Div. 2) A】Key races
[Link]:http://codeforces.com/contest/835/problem/A [Description] [Solution] 傻逼题. [NumberOf WA] [Revi ...
随机推荐
- [0] 服务器 TCP 提供程序无法在 [ 'any' <ipv4> *] 上侦听。TCP 端口已在使用中。
配置工具——配置管理器——SQLEXPRESS协议下的TCP/IP协议 将其已启用改为禁用. 同时停止SQLEXPRESS服务即可
- MVC在VIEW中动态控制htmlAttributes的方法
@{ IDictionary<string, object> dic = new Dictionary<string, object>(); dic.Add("cla ...
- C# DataGridView显示日期格式问题
给DataGridView单元格绑定或者赋值DataTime数据后有时会发现不能显示完整的数据格式,怎么办呢?给出解决方案如下:1.指定整列的显示格式:m_dataGridView.Columns[c ...
- drozer使用
1.启用adb 端口转发 adb forward tcp:314154 tcp:31415 2.启用drozer 3.链接drozer drozer console connect 4:如果没 ...
- R语言包翻译
Shiny-cheatsheet 作者:周彦通 1.安装 install.packages("shinydashboard") 2.基础知识 仪表盘有三个部分:标题.侧边栏,身体 ...
- qt中setStyleSheet导致的内存泄漏
原始日期: 2017-01-05 19:31 现象:程序运行至某一个界面下,内存出现缓慢持续的占用内存增长 原因:经过排查,确定是在事件派发的槽函数中频繁重复调用setStyleSheet导致的 ...
- 【解决】安装compass失败(gem install compass)
原始日期:2016-01-25 16:26 这个问题比较常见. 很多人在安装ruby后再使用gem install compass命令安装compass,发现安装失败. [解决方法:] / ...
- 页面加载的时候自动的执行js代码
<script> window.onload=MyAutoRun; function MyAutoRun(){ alert("函数自动执行哦!"); } </sc ...
- ECMAScript 6 中的快捷语法汇总及代码示例
对于每个 JavaScript 开发人员,快捷语法都是必备技能之一,下面就集中介绍这些快捷语法. 三元运算符 传统写法 const x = 20; let answer; if (x > 10) ...
- React 在服务端渲染的实现
原文地址:Server-Side React Rendering 原文作者:Roger Jin 译者:牧云云 React 在服务端渲染的实现 React是最受欢迎的客户端 JavaScript 框架, ...