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*2],dp[N];

int num[11];

void read(int &x)
{
    x=0; char c=getchar();
    while(!isdigit(c)) c=getchar();
    while(isdigit(c)) { x=x*10+c-‘0‘; c=getchar(); }
}

int main()
{
    int odd,even;
    int x,len;
    int m=N-1<<1;
    for(int i=1;i<=m;++i)
    {
        odd=even=0;
        x=i;
        len=0;
        while(x) num[++len]=x%10,x/=10;
        for(int j=1;j<=len;++j)
        {
            if(num[j]&1) odd+=num[j];
            else even+=num[j];
        }
        sum[i]=abs(odd-even)+sum[i-1];
    }
    for(int i=1;i<N;++i) dp[i]=dp[i-1]+(sum[i*2]-sum[i])*2-(sum[i*2]-sum[i*2-1]);
    int T,n;
    read(T);
    while(T--)
    {
        read(n);
        cout<<dp[n]<<‘\n‘;
    }
} 

Read problems statements in Mandarin chineseRussian 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
时间: 2024-10-17 14:22:45

CF&&CC百套计划2 CodeChef December Challenge 2017 Total Diamonds的相关文章

CF&amp;&amp;CC百套计划2 CodeChef December Challenge 2017 Chef And his Cake

https://www.codechef.com/DEC17/problems/GIT01 #include<cstdio> #include<algorithm> using namespace std; #define N 101 char s[N]; int main() { int T; scanf("%d",&T); int n,m; int OddG,OddR,EvenG,EvenR; int ans; while(T--) { OddG=O

CF&amp;&amp;CC百套计划2 CodeChef December Challenge 2017 Chef and Hamming Distance of arrays

https://www.codechef.com/DEC17/problems/CHEFHAM #include<cstdio> #include<cstring> #include<iostream> using namespace std; #define N 100001 int a[N],b[N]; int sum[N],wh[N][2]; int num1[N],num2[N]; void read(int &x) { x=0; char c=getc

CF&amp;&amp;CC百套计划2 CodeChef December Challenge 2017 Penalty Shoot-out

https://www.codechef.com/DEC17/problems/CPLAY #include<cstdio> #include<algorithm> using namespace std; char s[21]; int main() { int sumA,sumB; while(scanf("%s",s+1)!=EOF) { sumA=sumB=0; int i; for(i=1;i<=10;++i) { if(i&1) { i

CF&amp;&amp;CC百套计划3 Codeforces Round #204 (Div. 1) D. Jeff and Removing Periods

http://codeforces.com/problemset/problem/351/D 题意: n个数的一个序列,m个操作 给出操作区间[l,r], 首先可以删除下标为等差数列且数值相等的一些数 然后可以对区间剩余数重排 继续删除下标为等差数列且数值相等的一些数 继续对区间进行重排 直至区间内没有数 问每次操作的最少删除次数 因为每次删除后可以重排 那么完全可以在第一次删除后就把区间相等的数排在一起 这样相等的数的下标就分别构成了公差为1的等差数列 所以问题转化为 设区间[l,r]内数有x

CF&amp;&amp;CC百套计划3 Codeforces Round #204 (Div. 1) A. Jeff and Rounding

http://codeforces.com/problemset/problem/351/A 题意: 2*n个数,选n个数上取整,n个数下取整 最小化 abs(取整之后数的和-原来数的和) 先使所有的数都下取整,累积更改的sum 那么选1个小数上取整,就会使sum-1 整数上下取整不会产生影响 所以有1个整数就可以使上取整的小数少1个 所以ans=min(abs(i-sum)) i∈[n-整数个数,n] #include<cmath> #include<cstdio> #inclu

Codechef December Challenge 2014 Chef and Apple Trees 水题

Chef and Apple Trees Chef loves to prepare delicious dishes. This time, Chef has decided to prepare a special dish for you, and needs to gather several apples to do so. Chef has N apple trees in his home garden. Each tree has a certain (non-zero) num

[codechef July Challenge 2017] IPC Trainers

IPCTRAIN: 训练营教练题目描述本次印度编程训练营(Indian Programming Camp,IPC)共请到了 N 名教练.训练营的日程安排有 M 天,每天最多上一节课.第 i 名教练在第 Di 天到达,直到训练营结束才离开.第 i 名教练希望上 Ti 节课.要是少上了课,那么教练会感到扎心,每少上一节,扎心值就会加 Si.作为主办方,你希望最小化所有教练的扎心值之和.输入格式输入的第一行包含一个整数 T,代表测试数据的组数.接下来是 T 组数据.每组数据的第一行包含两个整数 N 和

[codechef July Challenge 2017] Chef and Sign Sequences

CHEFSIGN: 大厨与符号序列题目描述大厨昨天捡到了一个奇怪的字符串 s,这是一个仅包含'<'.'='和'>'三种比较符号的字符串.记字符串长度为 N,大厨想要在字符串的开头.结尾,和每两个字符之间插入一个正整数,共N + 1 个数.大厨希望插入数字之后,这些比较符号所表达的含义是正确的.举个例子,如果在'<'前后分别插入 a 和 b,那么应当有 a < b.对于'='和'>'也是类似的.大厨可以在 [1, P] 中任意选择数字插入,同一个数也可以被插入到多个位置.请你帮

[codechef July Challenge 2017] Calculator

CALC: 计算器题目描述大厨有一个计算器,计算器上有两个屏幕和两个按钮.初始时每个屏幕上显示的都是 0.每按一次第一个按钮,就会让第一个屏幕上显示的数字加 1,同时消耗 1 单位的能量.每按一次第二个按钮,会让第二个屏幕上显示的数字加上第一个屏幕上显示的数字,同时消耗 B 单位的能量.初始时,计算器有 N 单位的能量.大厨想知道在能量限制下,第二个屏幕上最大可以出现的数字是多少?输入格式输入的第一行包含一个整数 T,代表测试数据的组数.接下来是 T 组数据.每组数据仅有一行,包含两个整数 N