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 ...
随机推荐
- 动态分配数组(new)和用随机数赋值(rand)
#include <iostream>#include <ctime>#include <cstdlib>using namespace std; int main ...
- PHPCMS v9 自定义表单添加验证码
1. 在 \phpcms\templates\default\formguide\show.html 中添加验证码显示 <input type="text" id=&quo ...
- Java学习笔记--监视目录变化
1.在实际开发中可能会需要监视某个目录下的文件所发生的变化. 2.在java7之前的做法 在一个独立的线程中使用File类的listFiles方法来定时检查目录中的内容,并与之前的内容进行比较 ...
- Socket实现
网络实现架构 4.4BSD通过同时对多种通信协议的支持来提供通用的底层基础服务.4.4BSD支持四种不同的通信协议簇: TCP/IP(互联网协议簇) XNS(Xerox网络系统) OSI协议 Unix ...
- Vue.js 介绍入门
Vue.js 的目标 是通过尽可能简单的 API 实现响应的数据绑定和组合的视图组件.Vue.js 是一个用于创建 Web 交互界面的库.它让你通过简单而灵活的 API 创建由数据驱动的 UI 组件. ...
- [leetcode-563-Binary Tree Tilt]
Given a binary tree, return the tilt of the whole tree.The tilt of a tree node is defined as the abs ...
- NEWS-包名-baseTest-类名-baeseDao
package baseTest; import java.sql.Connection;import java.sql.DriverManager;import java.sql.PreparedS ...
- 原生封装ajax
01.声明一个全局变量 02.开始封装,判断参数 03.属性的var自定义 04.请求 01.请求行 02.请求头 03.请求发送 05.响应 01.事件监听onreadystatechange 02 ...
- Vulkan Tutorial 27 combined image sampler
操作系统:Windows8.1 显卡:Nivida GTX965M 开发工具:Visual Studio 2017 Introduction 我们在教程的uniform 缓冲区中首次了解了描述符.在本 ...
- Unity3D Image 组件附入图片问题
作为新手经常会看到有个Image的组件 代码中理所当然的public 发现图片并不能附入其中, 解决办法直接 public Sprite 就可以了