UESTC 2018 Summer Training #6 Div.2

A

小Hi在玩一种牌类游戏,每张牌的属性值可以看成一个三元组(Ai, Bi, Ci),我们定义一张牌 (p1, p2, p3) 比 (q1, q2, q3)大,当且仅当集合{1, 2, 3}中有至少两个数x满足px>qx

例如 (5, 1, 3) 比 (4, 10000, 2) 大

现在小Hi获得了一种特殊能力,他能在比大小之前,随便改变自己的牌的属性的顺序,例如将 (1,2,3) 改成 (2,3,1),注意是每次比大小之前都可以改变

现在小Hi一共有 n 张牌,他想知道有几张牌满足,用特殊能力和剩下的牌比大小的话都是它大

Input

第一行一个正整数n

接下来 n 行,每行三个正整数a, b, c,表示一张牌(a,b,c)

1 ≤ n ≤ 2×105

1 ≤ a, b, c ≤ 109

保证所有 a, b, c 互不相同

Output

输出有几张牌满足条件

 

Sample Input

4
5 9 10
2 12 4
8 7 3
6 11 1

Sample Output

2

水题:

如果要判断这个是不是保证比其他的大,找到所有序列各自最小值和次小值的最大值,只要这个序列的最大值比最小值的最大值大,次大值大于等于次小值的最大值大,就是满足条件的。

#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<string>
#include<algorithm>
#include<vector>
#include<queue>
#include<set>
#include<map>
#include<stack>

#define MOD 10000000
using namespace std; 
typedef long long LL;
typedef unsigned long long ULL;
ULL base=233;
void read(int &x)//'&'表示引用,也就是说x是一个实参,在函数中改变了x的值就意味着在外面x的值也会被改变
{
    int f=1;//标记正负
    x=0;//归零(这就是潜在bug,有可能传进来时x没有归零)
    char s=getchar();//读入第一个字符
    while(s<'0'||s>'9')//不是数字字符
    {
        if(s=='-')//不能直接把f=-1,有可能输入的不是'-'而是其他乱七八糟的东西
            f=-1;
        s=getchar();//继续读
    }
    while(s>='0'&&s<='9')//是字符(一旦不是字符就意味着输入结束了)
    {
        x=x*10+s-'0';
        s=getchar();
    }
    x*=f;//改变正负
}
long long quickpow(long long n, long long base) {
    long long res = 1;
    while(n) {
        if(n & 1) {
            res = res * base % MOD;
        }
        n >>= 1;
        base = base * base % MOD;
    }
    return res;
}//快速幂 
ULL HASH(char s[])
{
	int l=strlen(s);
	ULL ans=0;
	for(int i=0;i<l;i++)
	{
		ans=ans*base+(ULL)s[i];
	}
	return ans;
}
set<ULL>hash0;//手动哈希 
set<ULL>::iterator it;//STL迭代器 

set<int >set0;
struct 
{
	LL max1;
	LL max2;
}A[200050];
int main()
{
   int n;
   cin>>n;
   LL a,b,c;
   LL min1=-1000,min2=-1000;
   LL e,d,f,h;
   for(int i=1;i<=n;i++)
   {
   	  scanf("%lld%lld%lld",&a,&b,&c);
   	  e=min(a,b);
   	  d=min(b,c);
   	  if(e==d)
   	  {
  	   	 d=min(a,c);
      }
      if(e>d)
      {
      	 LL temp=e;
      	 e=d;
      	 d=temp;
      }
      min1=max(min1,e);
      min2=max(min2,d);
 
      e=max(a,b);
      d=max(b,c);
      if(e==d)
      {
      	if(a<c)
      	d=c;
      	else d=a;
      }
      if(e<d)
      {
      	 LL temp=e;
      	 e=d;
      	 d=temp;
      }
      A[i].max1=e;
      A[i].max2=d;
   }
   LL ans=0;
   for(int i=1;i<=n;i++)
   {
   	  if(A[i].max1>=min2&&A[i].max2>=min1)
   	  {ans++;}
   }
   cout<<ans<<endl;
}

G

A city is built on the top of a rectangular n × m grid where all the grid cells are equal squares. Each of the n·m grid cells can serve as a foundation of a single building in the city. A building is represented as a number of 1 × 1 × 1 cubes stacked on the top of each other. The cube that lays in the foundation of a building entirely occupies a single cell on the grid. It is clear that adjacent buildings can share a wall or a part of it. Typical cities can be seen on the image below.

The King of Berland has a 3D model of the capital city in his office. This model was made on a special 3D-printer out of plastic. It represents a layout of the capital city, but the scale is smaller, so it's very convenient for the King to examine the model without having to visit the city itself. The King is bored though because the model is colorless, so he wants to paint the model. To calculate the exact amount of required paint he should know the total area of the model's surface.

You have to help the King and write a program that will calculate the required surface area of the given model. While calculating the surface area you should count not only the side surfaces, but also the areas of the top and bottom facets.

The model is given to you as n × m matrix of digits. A digit in the j-th position of the i-th row stands for the height of the building with its foundation in cell (i, j) of the model. If the corresponding digit is equal to "0", it means there is no building built on the top of this cell.

Input

The first line of input contains a pair of integers n, m (1 ≤ n, m ≤ 100), where n — amount of rows in the given grid, m — amount of columns. The following n lines contain the description of the model. These n lines contain m digits each representing heights of the buildings. It's guaranteed that the given matrix contains at least one non-zero digit.

Output

Output the only positive integer — surface area of the model.

Examples

Input

3 3
111
212
111

Output

38

Input

3 4
1000
0010
0000

Output

12

Note

The first sample test corresponds to the leftmost picture from the problem statement.

讨论一下,右边的比左边高的时候多出来几面,比左边低的时候多出来几面。

上下也是,先处理第一行第一列然后递推最后得出答案。

#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<string>
#include<algorithm>
#include<vector>
#include<queue>
#include<set>
#include<map>
#include<stack>

#define MOD 10000000
using namespace std; 
typedef long long LL;
typedef unsigned long long ULL;
ULL base=233;
void read(int &x)//'&'表示引用,也就是说x是一个实参,在函数中改变了x的值就意味着在外面x的值也会被改变
{
    int f=1;//标记正负
    x=0;//归零(这就是潜在bug,有可能传进来时x没有归零)
    char s=getchar();//读入第一个字符
    while(s<'0'||s>'9')//不是数字字符
    {
        if(s=='-')//不能直接把f=-1,有可能输入的不是'-'而是其他乱七八糟的东西
            f=-1;
        s=getchar();//继续读
    }
    while(s>='0'&&s<='9')//是字符(一旦不是字符就意味着输入结束了)
    {
        x=x*10+s-'0';
        s=getchar();
    }
    x*=f;//改变正负
}
long long quickpow(long long n, long long base) {
    long long res = 1;
    while(n) {
        if(n & 1) {
            res = res * base % MOD;
        }
        n >>= 1;
        base = base * base % MOD;
    }
    return res;
}//快速幂 
ULL HASH(char s[])
{
	int l=strlen(s);
	ULL ans=0;
	for(int i=0;i<l;i++)
	{
		ans=ans*base+(ULL)s[i];
	}
	return ans;
}
set<ULL>hash0;//手动哈希 
set<ULL>::iterator it;//STL迭代器 

int A[1500][1500];
int main()
{
	freopen("input.txt","r",stdin);
	freopen("output.txt","w",stdout);
	 int n,m;
	 cin>>n>>m;
     for(int i=1;i<=n;i++)
     {
     	for(int j=1;j<=m;j++)
     	{
	     	scanf("%1d",&A[i][j]);
        }
     }
     int ans;
	 if(A[1][1])
     ans=4*A[1][1]+2;
     else ans=0;
 	 for(int j=2;j<=m;j++)
 	 {    
 	 	 if(A[1][j]>A[1][j-1])
 	 	 ans+=4*A[1][j]+2-2*A[1][j-1];
 	 	 else ans+=2*A[1][j]+2;
 	 	 if(A[1][j]==0)ans-=2;
		   //cout<<ans<<endl;	 
 	 }
 	 for(int i=2;i<=n;i++)
 	 {
 	 	if(A[i][1]>A[i-1][1])
 	 	ans+=4*A[i][1]+2-2*A[i-1][1];
 	 	else ans+=2*A[i][1]+2;
 	 	if(A[i][1]==0)ans-=2;
 	 	//cout<<ans<<endl;
 	 }
 	 for(int i=2;i<=n;i++)
 	 {
 	 	for(int j=2;j<=m;j++)
 	 	{
	 	 	if(A[i][j]>A[i-1][j])
	 	 	{
	 	 		ans+=2*A[i][j]-2*A[i-1][j];
	 	 	}
	 	 	if(A[i][j]>A[i][j-1])
	 	 	{
	 	 		ans+=2*A[i][j]-2*A[i][j-1];
	 	 	}
	 	 	ans+=2;
	 	 	if(A[i][j]==0)ans-=2;
	 	 	//cout<<ans<<endl;
 	    }
 	 }
 	 cout<<ans<<endl;
 	fclose(stdin);
 	fclose(stdout);
 	return 0;
}

这题肯定是做烦了的,实际上我们把初始面积都加上然后,如果有重合的面积,实际上是两面,小面+大面,只考虑这个重复部分的表面积就只有大面-小面=大面+小面-两个小面,特殊情况,大面=小面,这时候为0符合,所以每一步加上全部表面积之后,再减去重合部分的小面即可,(PS:遍历一遍,重合部分总是会出现两次,所以会减两次)

这里是参考了这个题解

https://blog.csdn.net/dt2131/article/details/62054181


#include <bits/stdc++.h>

 

using namespace std;

int a[105][105];

char x;

int dirx[4]={1,0,-1,0};

int diry[4]={0,1,0,-1};

int main()

{

    freopen("input.txt","r",stdin);

    freopen("output.txt","w",stdout);

    int n,m;

    while(cin>>n>>m){

        long long ans=0;

        memset(a,0,sizeof(a));

        for(int i=1;i<=n;i++){

            for(int j=1;j<=m;j++){

                cin>>x;

                x-='0';

                a[i][j]=x;

            }

        }

        for(int i=1;i<=n;i++)

        for(int j=1;j<=m;j++){

            if(a[i][j]) ans+=4*a[i][j]+2;

            for(int k=0;k<4;k++){

                ans-=min(a[i+dirx[k]][j+diry[k]],a[i][j]);

            }

        }

        cout<<ans<<endl;

    }

}


 

B题

设 f(n) 表示 n 的每一位数字的平方之和,求 [a,b] 中有几个 n 满足 k × f(n)=n

Input

第一行三个正整数 k, a, b

1 ≤ k, a, b ≤ 1018,且a ≤ b

Output

输出一个非负整数,表示解的个数

 

Sample Input

5 10 20

Sample Output

1

这道题呢,数位DP,暴力搜索都可以过(我会分到两个专题里去)

数位DP做:https://blog.csdn.net/mxYlulu/article/details/81264552

暴力搜索做:https://blog.csdn.net/mxYlulu/article/details/81264503

 

E题

An array of positive integers a1, a2, ..., an is given. Let us consider its arbitrary subarray al, al + 1..., ar, where 1 ≤ l ≤ r ≤ n. For every positive integer s denote by Ks the number of occurrences of s into the subarray. We call the power of the subarray the sum of products Ks·Ks·s for every positive integer s. The sum contains only finite number of nonzero summands as the number of different values in the array is indeed finite.

You should calculate the power of t given subarrays.

Input

First line contains two integers n and t (1 ≤ n, t ≤ 200000) — the array length and the number of queries correspondingly.

Second line contains n positive integers ai (1 ≤ ai ≤ 106) — the elements of the array.

Next t lines contain two positive integers l, r (1 ≤ l ≤ r ≤ n) each — the indices of the left and the right ends of the corresponding subarray.

Output

Output t lines, the i-th line of the output should contain single positive integer — the power of the i-th query subarray.

Please, do not use %lld specificator to read or write 64-bit integers in C++. It is preferred to use cout stream (also you may use %I64d).

Examples

Input

3 2
1 2 1
1 2
1 3

Output

3
6

Input

8 3
1 1 2 2 1 3 1 1
2 7
1 6
2 7

Output

20
20
20

Note

Consider the following array (see the second sample) and its [2, 7] subarray (elements of the subarray are colored):

Then K1 = 3, K2 = 2, K3 = 1, so the power is equal to 32·1 + 22·2 + 12·3 = 20.

莫队板题

https://blog.csdn.net/mxylulu/article/details/81260753

C题

小 Hi 手上有 n 张面值互不相同的钱币,且面值都是 2 的幂次,现在他想知道,他可以组合出多少种小于等于 c 的正整数金额。

Input

第一行两个正整数 n , c  (1 ≤ n ≤ 50, 1 ≤ c ≤ 1018)

第二行n个互不相同的正整数,表示小Hi手上钱币的面值,保证面值都是 2 的幂次,且不超过 1018

Output

输出一个整数表示答案

 

Sample Input

3 10
4 1 8

Sample Output

5

Hint

可以拼出 1, 4, 5, 8, 9

这道题转换为二进制,然后数位DP,精彩!

https://blog.csdn.net/mxYlulu/article/details/81264552

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值