codeforces835 b贪心 c 二维前缀和
来源:互联网 发布:php中的错误类型有哪些 编辑:程序博客网 时间:2024/05/20 10:10
Some natural number was written on the board. Its sum of digits was not less thank. But you were distracted a bit, and someone changed this number ton, replacing some digits with others. It's known that the length of the number didn't change.
You have to find the minimum number of digits in which these two numbers can differ.
The first line contains integer k (1 ≤ k ≤ 109).
The second line contains integer n (1 ≤ n < 10100000).
There are no leading zeros in n. It's guaranteed that this situation is possible.
Print the minimum number of digits in which the initial number and n can differ.
311
1
399
0
In the first example, the initial number could be 12.
In the second example the sum of the digits of n is not less thank. The initial number could be equal to n.
#include <iostream>#include <cstdio>#include <string.h>#include <algorithm>#define LL long longusing namespace std;const int AX = 1e6;char a[AX];int b[AX];int main(){int k ;scanf("%d",&k);scanf("%s",a);int len = strlen(a);int ans = 0;for( int i = 0 ; i < len ; i++ ){ans += (a[i] - '0');if( ans >= k ) {printf("0\n");return 0;}b[i] = a[i] - '0';}sort(b,b+len);int temp = k - ans;for( int i = 0 ; i < len ; i++ ){temp -= (9-b[i]);if( temp <= 0 ) {printf("%d\n",i+1); return 0;}}return 0;}
The Cartesian coordinate system is set in the sky. There you can see n stars, the i-th has coordinates (xi,yi), a maximum brightnessc, equal for all stars, and an initial brightnesssi (0 ≤ si ≤ c).
Over time the stars twinkle. At moment 0 the i-th star has brightness si. Let at momentt some star has brightnessx. Then at moment (t + 1) this star will have brightnessx + 1, ifx + 1 ≤ c, and0, otherwise.
You want to look at the sky q times. In thei-th time you will look at the momentti and you will see a rectangle with sides parallel to the coordinate axes, the lower left corner has coordinates (x1i,y1i) and the upper right — (x2i,y2i). For each view, you want to know the total brightness of the stars lying in the viewed rectangle.
A star lies in a rectangle if it lies on its border or lies strictly inside it.
The first line contains three integers n,q,c (1 ≤ n, q ≤ 105,1 ≤ c ≤ 10) — the number of the stars, the number of the views and the maximum brightness of the stars.
The next n lines contain the stars description. Thei-th from these lines contains three integersxi,yi,si (1 ≤ xi, yi ≤ 100,0 ≤ si ≤ c ≤ 10) — the coordinates ofi-th star and its initial brightness.
The next q lines contain the views description. Thei-th from these lines contains five integersti,x1i,y1i,x2i,y2i (0 ≤ ti ≤ 109,1 ≤ x1i < x2i ≤ 100,1 ≤ y1i < y2i ≤ 100) — the moment of thei-th view and the coordinates of the viewed rectangle.
For each view print the total brightness of the viewed stars.
2 3 31 1 13 2 02 1 1 2 20 2 1 4 55 1 1 5 5
303
3 4 51 1 22 3 03 3 10 1 1 100 1001 2 2 4 42 2 1 4 71 50 50 51 51
3350
Let's consider the first example.
At the first view, you can see only the first star. At moment 2 its brightness is 3, so the answer is 3.
At the second view, you can see only the second star. At moment 0 its brightness is 0, so the answer is 0.
At the third view, you can see both stars. At moment 5 brightness of the first is2, and brightness of the second is1, so the answer is 3.
#include <iostream>#include <cstdio>#include <string.h>#include <algorithm>#define LL long longusing namespace std;int a[15][200][200];int main(){int n , q , c;scanf("%d%d%d",&n,&q,&c);int x,y,s;while( n-- ){scanf("%d%d%d",&x,&y,&s);for( int i = 0 ; i <= 10 ; i++ )a[i][x][y] += ( s + i )%( c + 1 ) ;}for( int k = 0 ; k <= 10 ; ++k){for(int i = 1 ; i <= 100 ; i++ ){for( int j = 1 ; j <=100 ; j++ ){a[k][i][j] += a[k][i-1][j] + a[k][i][j-1] -a[k][i-1][j-1];}}}int t, x1, y1, x2, y2; while( q -- ){int ans = 0;scanf("%d%d%d%d%d",&t,&x1,&y1,&x2,&y2);t %= ( c + 1 );ans = a[t][x2][y2] - a[t][x1-1][y2]-a[t][x2][y1-1]+a[t][x1-1][y1-1];printf("%d\n",ans);}return 0;}
- codeforces835 b贪心 c 二维前缀和
- codeforces835 C
- 二维前缀和 codeforces 832C
- codeforces 835C(二维前缀和)
- Codeforces 828B Black Square【暴力枚举+二维前缀和】
- 二维前缀和
- 二维前缀和
- Codeforces 611C:New Year and Domino 二维前缀和
- Codeforces 611C:New Year and Domino 二维前缀和
- codeforces 835C Star sky (二维数组前缀和)
- Codeforces 853C Star sky(二维前缀和)
- B. Fence----前缀和
- BZOJ 1218 二维前缀和
- CF-608B 前缀和
- CS R14 C(模拟+二维前缀和) ,D(好题,前缀第i位异或+滑动区间),E(树计数+DP(前缀和优化))
- 611C. New Year and Domino【二维前缀和】【容斥】
- AGC 015C Nuske vs Phantom Thnook 思维+二维前缀和
- Codeforces Round #427 (Div. 2)-C. Star sky(二维前缀和)
- http 请求工具
- C# 程序员最常犯的 10 个错误 【已翻译100%】 英文原文:Top 10 Mistakes that C# Programmers Make 标签: C# oschina 推荐于 3年前 (共
- MIMO技术杂谈(一):鱼与熊掌能否兼得?--浅谈分集与复用的权衡
- 怎样从0开始搭建一个测试框架_7——接口
- CSS动画(补充一些常用写法)
- codeforces835 b贪心 c 二维前缀和
- UWA发布 | 2017 Unity手游体检蓝皮书 — ARPG篇
- Ubuntu16.04 安装流程 -2 常用软件及配置(201705)
- 字符串排序-变形题
- java动态代理(JDK和cglib)
- Struts2学习笔记(六)——Action访问Servlet API
- HDU6058 (76/600)
- java操作hbase
- uva 11093