2015长春区域赛

写一下水题题解:

还有没补完的。

F - Almost Sorted Array

e are all familiar with sorting algorithms: quick sort, merge sort, heap sort, insertion sort, selection

sort, bubble sort, etc. But sometimes it is an overkill to use these algorithms for an almost sorted array.

We say an array is sorted if its elements are in non-decreasing order or non-increasing order. We

say an array is almost sorted if we can remove exactly one element from it, and the remaining array is

sorted. Now you are given an array

a1,a2, . . . ,an, is it almost sorted?

Input

The rst line contains an integer

T

indicating the total number of test cases. Each test case starts with

an integer n in one line, then one line with

n

integers

a1,a2, . . . ,an•1

T

2000•2n105•1ai

10

5

There are at most 20 test cases with

n>

1000.

Output

For each test case, please output `

YES

' if it is almost sorted. Otherwise, output `

NO

' (both without

quotes).

Sample Input

3

3

2 1 7

3

3 2 1

5

3 1 4 1 5

Sample Output

YES

YES

NO

题意:

去掉一个数字后看剩下的是否是不下降,不上升或者相同的序列。

//最长不下降子序列nlogn  Song

#include<cstdio>
#include<algorithm>
using namespace std;

int a[400005];
int d[400005];
int dd[400005];
int main()
{
    int n;
    int t;
    scanf("%d",&t);
    while(t--){
    scanf("%d",&n);
    for (int i=1;i<=n;i++) scanf("%d",&a[i]);
    d[1]=a[1];  //初始化
    dd[1]=-a[1];
    int len1=1;
    int len2=1;
    for (int i=2;i<=n;i++)
    {
        if (a[i]>=d[len1]) d[++len1]=a[i];  //如果可以接在len后面就接上,如果是最长上升子序列,这里变成>
        else  //否则就找一个最该替换的替换掉
        {
            int j=upper_bound(d+1,d+len1+1,a[i])-d;  //找到第一个大于它的d的下标,如果是最长上升子序列,这里变成lower_bound
            d[j]=a[i];
        }
    }
     for (int i=2;i<=n;i++)
    {
        if (-a[i]>=dd[len2]) dd[++len2]=-a[i];  //如果可以接在len后面就接上,如果是最长上升子序列,这里变成>
        else  //否则就找一个最该替换的替换掉
        {
            int j=upper_bound(dd+1,dd+len2,-a[i])-dd;  //找到第一个大于它的d的下标,如果是最长上升子序列,这里变成lower_bound
            dd[j]=-a[i];
        }
    }

   /// printf("%d\n",len);
    if(len1==n-1|| len1==n || len2==n-1 || len2==n){
        printf("YES\n");
    }
    else
        printf("NO\n");
    }
    return 0;
}

L - House Building

Have you ever played the video game Minecraft? This game has been one of the world's most popular game in recent years. The world of Minecraft is made up of lots of 1×1×1 blocks in a 3D map. Blocks are the basic units of structure in Minecraft, there are many types of blocks. A block can either be a clay, dirt, water, wood, air, ... or even a building material such as brick or concrete in this game.

Nyanko-san is one of the diehard fans of the game, what he loves most is to build monumental houses in the world of the game. One day, he found a flat ground in some place. Yes, a super flat ground without any roughness, it's really a lovely place to build houses on it. Nyanko-san decided to build on a n\times mn×m big flat ground, so he drew a blueprint of his house, and found some building materials to build.

While everything seems goes smoothly, something wrong happened. Nyanko-san found out he had forgotten to prepare glass elements, which is a important element to decorate his house. Now Nyanko-san gives you his blueprint of house and asking for your help. Your job is quite easy, collecting a sufficient number of the glass unit for building his house. But first, you have to calculate how many units of glass should be collected.

There are n rows and m columns on the ground, an intersection of a row and a column is a 1×1 square,and a square is a valid place for players to put blocks on. And to simplify this problem, Nynako-san's blueprint can be represented as an integer array ci,j(1 \le i\le n,1\le j\le m1≤i≤n,1≤j≤m). Which ci,j indicates the height of his house on the square of ii-th row and jj-th column. The number of glass unit that you need to collect is equal to the surface area of Nyanko-san's house(exclude the face adjacent to the ground).

Input Format

The first line contains an integer TT indicating the total number of test cases.

First line of each test case is a line with two integers n,mn,m.

The n lines that follow describe the array of Nyanko-san's blueprint, the ii-th of these lines has mm integers ci,1,ci,2,...,ci,m, separated by a single space.

• 1 \le T \le 501≤T≤50

• 1\le n,m\le 501≤n,m≤50

• 0 \le c_{i,j} \le 10000≤ci,j​≤1000

Output Format

For each test case, please output the number of glass units you need to collect to meet Nyanko-san's requirement in one line.

HINT

样例输入复制

2
3 3
1 0 0
3 1 2
1 1 0
3 3
1 0 1
0 0 0
1 0 1

样例输出复制

30
20

求表面积(除了底面)

思维题。

代码:

#include<bits/stdc++.h>
using namespace std;
typedef long long LL;
const int maxn=100;
int a[maxn][maxn];

int main()
{
    int t,n,m;
    scanf("%d",&t);
    while(t--){
        memset(a,0,sizeof(a));
        scanf("%d%d",&n,&m);
        for(int i=1;i<=n;i++){
            for(int j=1;j<=m;j++){
                scanf("%d",&a[i][j]);
            }
        }
        int ans=0;
        for(int i=1;i<=n;i++){
            for(int j=1;j<=m;j++){
                if(a[i][j]==0)
                    continue;
                ans++;
                ans+=max(a[i][j]-a[i-1][j],0);
                ans+=max(a[i][j]-a[i][j-1],0);
                ans+=max(a[i][j]-a[i+1][j],0);
                ans+=max(a[i][j]-a[i][j+1],0);
            }
        }
        cout<<ans<<endl;
    }

}

J - Chip Factory

John is a manager of a CPU chip factory, the factory produces lots of chips everyday. To manage large

amounts of products, every processor has a serial number. More speci cally, the factory produces

n

chips today, the

i

-th chip produced this day has a serial number

s

i

.

At the end of the day, he packages all the chips produced this day, and send it to wholesalers. More

specially, he writes a checksum number on the package, this checksum is de ned as below:

max

i;j;k

(

s

i

+

s

j

)

s

k

which

i

,

j

,

k

are three

different

integers between 1 and

n

. And

is symbol of bitwise XOR.

Can you help John calculate the checksum number of today?

Input

The rst line of input contains an integer

T

indicating the total number of test cases.

The rst line of each test case is an integer n, indicating the number of chips produced today. The

next line has

n

integers

s

1

,

s

2

, . . . ,

s

n

, separated with single space, indicating serial number of each

chip.

1

T

1000

3

n

1000

0

s

i

10

9

There are at most 10 testcases with

n >

100

Output

For each test case, please output an integer indicating the checksum number in a line.

Sample Input

2

3

1 2 3

3

100 200 300

Sample Output

6

40

居然是暴力??。。。

代码:

#include<bits/stdc++.h>
using namespace std;
typedef long long LL;
const int maxn=1000+100;
LL a[maxn];

int main()
{
    int t,n,m;
    scanf("%d",&t);
    while(t--){
        scanf("%d",&n);
        for(int i=1;i<=n;i++){
            scanf("%d",&a[i]);
        }
        LL ans=-1;

            for(int i=1;i<=n;i++){
            for(int j=i+1;j<=n;j++){
                if(i==j)
                    continue;
                for(int k=j+1;k<=n;k++){
                        ans=max(ans,((a[i]+a[j])^a[k]));
                         ans=max(ans,((a[k]+a[j])^a[i]));
                         ans=max(ans,((a[i]+a[k])^a[j]));




                }
            }
        }

        printf("%lld\n",ans);
    }

}

G - Dancing Stars on Me

The sky was brushed clean by the wind and the stars were cold in a black sky. What a wonderful

night. You observed that, sometimes the stars can form a regular polygon in the sky if we connect

them properly. You want to record these moments by your smart camera. Of course, you cannot stay

awake all night for capturing. So you decide to write a program running on the smart camera to check

whether the stars can form a regular polygon and capture these moments automatically.

Formally, a regular polygon is a convex polygon whose angles are all equal and all its sides have

the same length. The area of a regular polygon must be nonzero. We say the stars can form a regular

polygon if they are exactly the vertices of some regular polygon. To simplify the problem, we project

the sky to a two-dimensional plane here, and you just need to check whether the stars can form a

regular polygon in this plane.

Input

The rst line contains a integer

T

indicating the total number of test cases. Each test case begins with

an integer

n

, denoting the number of stars in the sky. Following

n

lines, each contains 2 integers

x

i

,

y

i

,

describe the coordinates of

n

stars.

1

T

300

3

n

100

 

开始后还以为是凸包。。

没用longlong一直wa。。

代码:

#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const long long inf=100000000000000000;
int n;
ll last;
struct node{
    ll x,y;
}a[110];
int vis[110];
int num;
int kaka,flag;
ll lala(node a,node b){
    return ((a.x-b.x)*(a.x-b.x)+(a.y-b.y)*(a.y-b.y));
}
void dfs(int x){
    if(num>=n-1){
        if(lala(a[x],a[1])!=last)
        {
            cout<<"NO"<<endl;
            kaka=1;
            return;
        }
        return ;
    }
    num++;
    ll chang=inf;
    int logal;
    for(int i=1;i<=n;i++){
        if(i==x||vis[i]==1){continue;}
        if(chang >lala(a[x],a[i]) ){
            logal=i;
            chang=lala(a[x],a[i]);
        }
    }
    vis[logal]=1;
    if(chang!=last && num>=2)
    {
        cout<<"NO"<<endl;
        kaka=1;
        return;
    }
    last=chang;
    dfs(logal);
}
int main()
{
    int t;
    scanf("%d",&t);
    while(t--){
        memset(vis,0,sizeof(vis));
        scanf("%d",&n);
        for(int i=1;i<=n;i++){
            scanf("%lld%lld",&a[i].x,&a[i].y);
        }
        ///double chang=inf;
        kaka=0;
        num=0;
        vis[1]=1;
        dfs(1);
        if(kaka==0){
            cout<<"YES"<<endl;
        }
    }
}

 

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值