CF&&CC百套计划2 CodeChef December Challenge 2017 Total Diamonds
https://www.codechef.com/DEC17/problems/VK18
#include<cstdio>
#include<iostream>
#include<algorithm> using namespace std; #define N 1000001 long long sum[N*],dp[N]; int num[]; void read(int &x)
{
x=; char c=getchar();
while(!isdigit(c)) c=getchar();
while(isdigit(c)) { x=x*+c-''; c=getchar(); }
} int main()
{
int odd,even;
int x,len;
int m=N-<<;
for(int i=;i<=m;++i)
{
odd=even=;
x=i;
len=;
while(x) num[++len]=x%,x/=;
for(int j=;j<=len;++j)
{
if(num[j]&) odd+=num[j];
else even+=num[j];
}
sum[i]=abs(odd-even)+sum[i-];
}
for(int i=;i<N;++i) dp[i]=dp[i-]+(sum[i*]-sum[i])*-(sum[i*]-sum[i*-]);
int T,n;
read(T);
while(T--)
{
read(n);
cout<<dp[n]<<'\n';
}
}
Read problems statements in Mandarin chinese, Russian andVietnamese as well.
Chef is so good at programming that he won almost all competitions. With all the prizes, Chef bought a new house. The house looks like a grid of size N (1-indexed) which consists of N × N rooms containing diamonds. For each room, the room number is equal to the sum of the row number and the column number.
The number of diamonds present in each room is equal to the absolute difference between the sum of even digits and sum of odd digits in its room number. For example, if the room number is 3216, then the number of diamonds present in that room will be |(2+6)-(3+1)| = 4.
You are given the number N. You have to print the total number of diamonds present in Chef's house.
Input
- The first line of the input contains a single integer T denoting the number of test cases. The description of T test cases follows.
- The only line of each test case contains a single integer N.
Output
For each test case, print the answer on a separate line.
Constraints
- 1 ≤ T ≤ 105
- 1 ≤ N ≤ 106
Subtasks
Subtask #1 (15 points):
- 1 ≤ T ≤ 10
- 1 ≤ N ≤ 1000
Subtask #2 (15 points):
- 1 ≤ T ≤ 10
- 1 ≤ N ≤ 106
Subtask #3 (70 points): original constraints
Example
Input: 3
1
2
3 Output: 2
12
36
CF&&CC百套计划2 CodeChef December Challenge 2017 Total Diamonds的更多相关文章
- CF&&CC百套计划2 CodeChef December Challenge 2017 Chef And Easy Xor Queries
https://www.codechef.com/DEC17/problems/CHEFEXQ 题意: 位置i的数改为k 询问区间[1,i]内有多少个前缀的异或和为k 分块 sum[i][j] 表示第 ...
- CF&&CC百套计划2 CodeChef December Challenge 2017 Chef and Hamming Distance of arrays
https://www.codechef.com/DEC17/problems/CHEFHAM #include<cstdio> #include<cstring> #incl ...
- CF&&CC百套计划2 CodeChef December Challenge 2017 Penalty Shoot-out
https://www.codechef.com/DEC17/problems/CPLAY #include<cstdio> #include<algorithm> using ...
- CF&&CC百套计划2 CodeChef December Challenge 2017 Chef And his Cake
https://www.codechef.com/DEC17/problems/GIT01 #include<cstdio> #include<algorithm> using ...
- CF&&CC百套计划4 Codeforces Round #276 (Div. 1) A. Bits
http://codeforces.com/contest/484/problem/A 题意: 询问[a,b]中二进制位1最多且最小的数 贪心,假设开始每一位都是1 从高位i开始枚举, 如果当前数&g ...
- CF&&CC百套计划4 Codeforces Round #276 (Div. 1) E. Sign on Fence
http://codeforces.com/contest/484/problem/E 题意: 给出n个数,查询最大的在区间[l,r]内,长为w的子区间的最小值 第i棵线段树表示>=i的数 维护 ...
- CF&&CC百套计划1 Codeforces Round #449 C. Willem, Chtholly and Seniorious (Old Driver Tree)
http://codeforces.com/problemset/problem/896/C 题意: 对于一个随机序列,执行以下操作: 区间赋值 区间加 区间求第k小 区间求k次幂的和 对于随机序列, ...
- CF&&CC百套计划3 Codeforces Round #204 (Div. 1) D. Jeff and Removing Periods
http://codeforces.com/problemset/problem/351/D 题意: n个数的一个序列,m个操作 给出操作区间[l,r], 首先可以删除下标为等差数列且数值相等的一些数 ...
- CF&&CC百套计划1 Codeforces Round #449 A. Nephren gives a riddle
http://codeforces.com/contest/896/problem/A 第i个字符串嵌套第i-1个字符串 求第n个字符串的第k个字母 dfs #include<map> # ...
随机推荐
- HDU 4405 Aeroplane chess 期望dp
题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=4405 Aeroplane chess Time Limit: 2000/1000 MS (Java/ ...
- python learning GUI
Hello world1 from tkinter import * # 第一步是导入Tkinter包的所有内容 class Application(Frame): # 第二步是从Frame派生一个A ...
- [BUAA_SE_2017]个人阅读作业 + 总结
个人阅读作业 银弹 银弹是指能让狼人一枪毙命的致命子弹,对于软件工程而言,我觉得是不存在银弹的.每一项软件开发都是极为特殊的,有特定的需求.特定的功能,如果存在银弹能够直击要害解决问题,那么软件的开发 ...
- PAT 1034 有理数四则运算
https://pintia.cn/problem-sets/994805260223102976/problems/994805287624491008 本题要求编写程序,计算2个有理数的和.差.积 ...
- Windows下获取文件的md5码的方法
1.certutil 命令简介 本来想找一个工具 算一个文件的md5 或者是sha 值来着. 找到一个说法是 可以使用 windows 自带的命令行来处理 具体命令 certutil -hashfil ...
- [转帖]Intel为何吊打AMD,先进半导体工艺带来什么?
Intel为何吊打AMD,先进半导体工艺带来什么? 2016-3-10 15:38 | 作者:Strike | 关键字:超能课堂,半导体工艺,CPU制程 分享到 按照摩尔定律的发 ...
- 【问底】徐汉彬:PHP7和HHVM的性能之争 (真是学到了很多)
来源:http://www.csdn.net/article/2014-12-25/2823234 作者:徐汉彬 摘要:近日,PHP7和HHVM的性能之争成为了一个讨论热点,但毫无疑问,它们都在提升P ...
- Idea(二) 解决IDEA卡顿问题及相关基本配置
一.IDEA太卡顿,设置使用IDEA的内存 在IDEA的安装目录下的bin目录下: 打开设置: 将idea.exe.vmoptions文件内由-server-Xms128m-Xmx512m-XX:Ma ...
- JVM内存模型一
JVM定义了若干个程序执行期间使用的数据区域.这个区域里的一些数据在JVM启动的时候创建,在JVM退出的时候销毁.而其他的数据依赖于每一个线程,在线程创建时创建,在线程退出时销毁. 程序计数器 程序计 ...
- delphi手动创建dataset并插入值
unit Unit1; interface uses Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants, Syste ...