A - A codeforces 714A

Description

Today an outstanding event is going to happen in the forest — hedgehog Filya will come to his old fried Sonya!

Sonya is an owl and she sleeps during the day and stay awake from minute l1 to minute r1 inclusive. Also, during the minute k she prinks and is unavailable for Filya.

Filya works a lot and he plans to visit Sonya from minute l2 to minute r2 inclusive.

Calculate the number of minutes they will be able to spend together.

Input

The only line of the input contains integers l1, r1, l2, r2 and k (1 ≤ l1, r1, l2, r2, k ≤ 1018, l1 ≤ r1, l2 ≤ r2), providing the segments of time for Sonya and Filya and the moment of time when Sonya prinks.

Output

Print one integer — the number of minutes Sonya and Filya will be able to spend together.

Sample Input

Input
1 10 9 20 1
Output
2
Input
1 100 50 200 75
Output
50

Hint

In the first sample, they will be together during minutes 9 and 10.

In the second sample, they will be together from minute 50 to minute 74 and from minute 76 to minute 100.

题意:小E要在白天去拜访S,S呢在白天只有(l1,r1)是醒着的,小E选择在(l2,r2)去拜访S,但是在第K分钟的时候,他们不能共处,问他们最多能一起相处多长时间

分析:这题其实就是找两个区间的交集啦,注意数据量要开long long,所以错了一发

分下面六种情况:

l2 r2 l1 r1

l1 r1 l2 r2

l1 l2 r1 r2

l2 l1 r2 r1

l1 l2 r2 r1

l2 l1 r1 r2

然后开写啦~是不是很简单

 #include<cstdio>
#include<algorithm>
#include<iostream>
#include<cstring>
#include<cmath>
using namespace std;
int main()
{
long long l1,r1,l2,r2,k;
while(~scanf("%lld %lld %lld %lld %lld",&l1,&r1,&l2,&r2,&k))
{
long long sum=;
if(l1>=l2&&r2>=r1)
{
sum=r1-l1+;
if(k>=l1&&k<=r1)
sum--;
}
else if(r2<l1||l2>r1)
{
sum=;
}
else if(l2<=l1&&r2>=l1&&r2<=r1)
{
sum=r2-l1+;
if(k<=r2&&k>=l1)
sum--;
}
else if(l2>=l1&&l2<=r1&&r2>=r1)
{
sum=r1-l2+;
if(k<=r1&&k>=l2)
sum--;
}
else if(l2>=l1&&r2<=r1)
{
sum=r2-l2+;
if(k>=l2&&k<=r2)
sum--;
}
printf("%lld\n",sum);
}
return ;
}

B - B

codeforces 1059B

Description

Student Andrey has been skipping physical education lessons for the whole term, and now he must somehow get a passing grade on this subject. Obviously, it is impossible to do this by legal means, but Andrey doesn't give up. Having obtained an empty certificate from a local hospital, he is going to use his knowledge of local doctor's handwriting to make a counterfeit certificate of illness. However, after writing most of the certificate, Andrey suddenly discovered that doctor's signature is impossible to forge. Or is it?

For simplicity, the signature is represented as an n×mn×m grid, where every cell is either filled with ink or empty. Andrey's pen can fill a 3×33×3 square without its central cell if it is completely contained inside the grid, as shown below.

xxx
x.x
xxx

Determine whether is it possible to forge the signature on an empty n×mn×m grid.

Input

The first line of input contains two integers nn and mm (3≤n,m≤10003≤n,m≤1000).

Then nn lines follow, each contains mm characters. Each of the characters is either '.', representing an empty cell, or '#', representing an ink filled cell.

Output

If Andrey can forge the signature, output "YES". Otherwise output "NO".

You can print each letter in any case (upper or lower).

Sample Input

Input
3 3
###
#.#
###
Output
YES
Input
3 3
###
###
###
Output
NO
Input
4 3
###
###
###
###
Output
YES
Input
5 7
.......
.#####.
.#.#.#.
.#####.
.......
Output
YES

Hint

In the first sample Andrey can paint the border of the square with the center in (2,2)(2,2).

In the second sample the signature is impossible to forge.

In the third sample Andrey can paint the borders of the squares with the centers in (2,2)(2,2) and (3,2)(3,2):

  1. we have a clear paper:

    ...
    ...
    ...
    ...
  2. use the pen with center at (2,2)(2,2).
    ###
    #.#
    ###
    ...
  3. use the pen with center at (3,2)(3,2).
    ###
    ###
    ###
    ###

In the fourth sample Andrey can paint the borders of the squares with the centers in (3,3)(3,3) and (3,5)(3,5).

题意:给你一个n*m的矩阵,问你这个矩阵是否可行,如果可以,则输出YES否则输出NO.一开始矩阵全由'.'组成,一个点只能影响它周围九个点,使其变为'#'.

分析:另外再开一个数组b,模拟一遍,如果数组a中存在周围九个点都是'#',则将b数组中对应的那九个点变为'#',最后判断a数组与b数组是否相等

#include<cstdio>
#include<algorithm>
#include<cstring>
#include<cmath>
#include<iostream>
using namespace std;
char a[][],b[][];
void judge(int i,int j)
{
int flag=;
for(int t=i-;t<=i+;t++)
for(int tt=j-;tt<=j+;tt++)
{
if(t==i&&tt==j)
continue;
if(a[t][tt]!='#')
{
flag=;
break;
}
}//判断周围九个点
if(flag==)
{
b[i-][j-]='#';
b[i-][j+]='#';
b[i][j-]='#';
b[i][j+]='#';
b[i+][j-]='#';
b[i+][j+]='#';
b[i-][j]='#';
b[i+][j]='#';
}//将b也染色
}
int main()
{
int n,m;
while(~scanf("%d %d",&n,&m))
{
getchar();
memset(b,'.',sizeof(b));//将b初始化
for(int i=;i<=n;i++)
{
for(int j=;j<=m;j++)
{
scanf("%c",&a[i][j]);
}
getchar(); }
for(int i=;i<=n;i++)
{
for(int j=;j<=m;j++)
{
if(i->=&&i+<=n&&j->=&&j+<=m)
judge(i,j);
}
}
int flag=;
for(int i=;i<=n;i++)
{
for(int j=;j<=m;j++)
{
if(a[i][j]!=b[i][j])
{
flag=;
break;
}
}
}//判断a数组与b数组是否相等
if(flag==)
printf("NO\n");
else
printf("YES\n");
}
return ;
}

D - D codeforces 714B

Description

Today, hedgehog Filya went to school for the very first time! Teacher gave him a homework which Filya was unable to complete without your help.

Filya is given an array of non-negative integers a1, a2, ..., an. First, he pick an integer x and then he adds x to some elements of the array (no more than once), subtract x from some other elements (also, no more than once) and do no change other elements. He wants all elements of the array to be equal.

Now he wonders if it's possible to pick such integer x and change some elements of the array using this x in order to make all elements equal.

Input

The first line of the input contains an integer n (1 ≤ n ≤ 100 000) — the number of integers in the Filya's array. The second line contains n integers a1, a2, ..., an (0 ≤ ai ≤ 109) — elements of the array.

Output

If it's impossible to make all elements of the array equal using the process given in the problem statement, then print "NO" (without quotes) in the only line of the output. Otherwise print "YES" (without quotes).

Sample Input

Input
5
1 3 3 2 1
Output
YES
Input
5
1 2 3 4 5
Output
NO

Hint

In the first sample Filya should select x = 1, then add it to the first and the last elements of the array and subtract from the second and the third elements.

题意:给你一个数组,可以选择对这个数组的某些数进行加x操作(只能操作一次)或者对这个数组里的某些数进行减x操作(只能操作一次),问是否能使整个数组里的所有数都相等,如果可以,输出YES,否则输出NO

分析:如果数组里不同的数的个数大于3时,一定输出NO,

如果数组里的不同的数的个数小于等于2时,一定输出YES

如果数组里的不同的数的个数刚好等于3时,

当最大的数和最小的数到中间那个数的距离相等的时候,他们加减的都是x,一定输出YES,否则输出NO

苍天啊啊啊,一定很注意细节的问题了,交题之前还专门瞄了一眼YESNO的大小写,没想到竟然是栽在N0上,被自己蠢哭了)

 #include<cstdio>
#include<algorithm>
#include<iostream>
#include<cstring>
#include<cmath>
using namespace std;
int main()
{
int n,a[],b[];
while(~scanf("%d",&n))
{
int k=;
for(int i=;i<=n;i++)
{
scanf("%d",&a[i]);
}
sort(a+,a++n);
b[]=a[];
int j=;
for(int i=;i<=n;i++)
{
if(a[i]!=a[i-])
{
k++;
b[j++]=a[i];
}//k其实就是来统计不同的数的个数的
}
int t=;
if(k==)
{
if(b[]-b[]==b[]-b[])
t=;
}当最大的数和最小的数到中间那个数的距离相等的时候
if(k<)//当不同的数的个数小于等于2时
t=;
if(k>||t==)
{
printf("NO\n");
}//当不同的数的个数大于3时
else
{
printf("YES\n");
} }
return ;
}

E - E codeforces714c

Description

Today Sonya learned about long integers and invited all her friends to share the fun. Sonya has an initially empty multiset with integers. Friends give her t queries, each of one of the following type:

  1.  + ai — add non-negative integer ai to the multiset. Note, that she has a multiset, thus there may be many occurrences of the same integer.
  2.  - ai — delete a single occurrence of non-negative integer ai from the multiset. It's guaranteed, that there is at least one ai in the multiset.
  3. ?s — count the number of integers in the multiset (with repetitions) that match some pattern s consisting of 0 and 1. In the pattern, 0 stands for the even digits, while 1 stands for the odd. Integer x matches the pattern s, if the parity of the i-th from the right digit in decimal notation matches the i-th from the right digit of the pattern. If the pattern is shorter than this integer, it's supplemented with 0-s from the left. Similarly, if the integer is shorter than the pattern its decimal notation is supplemented with the 0-s from the left.

For example, if the pattern is s = 010, than integers 92, 2212, 50 and 414 match the pattern, while integers 3, 110, 25 and 1030 do not.

Input

The first line of the input contains an integer t (1 ≤ t ≤ 100 000) — the number of operation Sonya has to perform.

Next t lines provide the descriptions of the queries in order they appear in the input file. The i-th row starts with a character ci — the type of the corresponding operation. If ci is equal to '+' or '-' then it's followed by a space and an integer ai (0 ≤ ai < 1018) given without leading zeroes (unless it's 0). If ci equals '?' then it's followed by a space and a sequence of zeroes and onse, giving the pattern of length no more than 18.

It's guaranteed that there will be at least one query of type '?'.

It's guaranteed that any time some integer is removed from the multiset, there will be at least one occurrence of this integer in it.

Output

For each query of the third type print the number of integers matching the given pattern. Each integer is counted as many times, as it appears in the multiset at this moment of time.

Sample Input

Input
12
+ 1
+ 241
? 1
+ 361
- 241
? 0101
+ 101
? 101
- 101
? 101
+ 4000
? 0
Output
2
1
2
1
1
Input
4
+ 200
+ 200
- 200
? 0
Output
1

题意:你有一个空数组,t次查询,每次查询有一个字符 c和数字a,如果c是‘+’,则把数字a加到数组中去(数组里的数字可以重复),如果c是‘-’,则把数字a从数组中删去(保证数组里一定会有数字a),如果c是‘?’,则在数组里查询有多少个数字a的奇偶性相同(a中的0代表偶数,1代表奇数),如果数组里的数字长度小于a时,则在数字的左边添零,同样,如果a的长度小于数组里的数字时,在a的左边添0,输出和a奇偶性相同的数的个数.

分析:如果直接用数组来存的话,会TLE的,所以选择用map来存,存之前得预处理一下,把数字a转换成1和0的形式

 #include<cstdio>
#include<algorithm>
#include<iostream>
#include<cstring>
#include<cmath>
#include<map>
using namespace std;
int main()
{
map<long long,int>m;
int t;
char c;
long long d;
scanf("%d",&t);
while(t--)
{
getchar();
scanf("%c%lld",&c,&d);
long long dd=,k=;
while(d)
{
if((d%)%==)
dd+=k*((d%)%);
k*=;
d/=;
}//预处理
// printf("%lld\n",dd);
if(c=='+')
{
m[dd]++;
}
else if(c=='-')
{
m[dd]--;
}
else
{
printf("%d\n",m[dd]);
}
}
return ;
}

2018SDIBT_国庆个人第六场的更多相关文章

  1. 2018SDIBT_国庆个人第七场

    A - Complete the Word(暴力) Description ZS the Coder loves to read the dictionary. He thinks that a wo ...

  2. 2018SDIBT_国庆个人第五场

    A - ACodeForces 1060A Description Let's call a string a phone number if it has length 11 and fits th ...

  3. 2018SDIBT_国庆个人第四场

    A - A  这题很巧妙啊,前两天刚好做过,而且就在博客里  Little C Loves 3 I time limit per test 1 second memory limit per test ...

  4. 2018SDIBT_国庆个人第三场

    A - A CodeForces - 1042A There are nn benches in the Berland Central park. It is known that aiai peo ...

  5. 山东省ACM多校联盟省赛个人训练第六场 poj 3335 D Rotating Scoreboard

    山东省ACM多校联盟省赛个人训练第六场 D Rotating Scoreboard https://vjudge.net/problem/POJ-3335 时间限制:C/C++ 1秒,其他语言2秒 空 ...

  6. noi.ac 第五场第六场

    t1应该比较水所以我都没看 感觉从思路上来说都不难(比牛客网这可简单多了吧) 第五场 t2: 比较套路的dp f[i]表示考虑前i个数,第i个满足f[i]=i的最大个数 i能从j转移需要满足 j< ...

  7. NOI.AC NOIP模拟赛 第六场 游记

    NOI.AC NOIP模拟赛 第六场 游记 queen 题目大意: 在一个\(n\times n(n\le10^5)\)的棋盘上,放有\(m(m\le10^5)\)个皇后,其中每一个皇后都可以向上.下 ...

  8. 2018SDIBT_国庆个人第二场

    A.codeforces1038A You are given a string ss of length nn, which consists only of the first kk letter ...

  9. 2018SDIBT_国庆个人第一场

    A - Turn the Rectangles CodeForces - 1008B There are nn rectangles in a row. You can either turn eac ...

随机推荐

  1. 查看设备uuid的命令-blkid

      查看设备uuid的命令-blkid 在关联/etc/fstab的时候可以使用   [root@mapper ~]# blkid /dev/sda1: UUID="285510be-b19 ...

  2. ubuntu 间简单相互通信

    1.  nc  命令 在一台机器上运行nc -l 来监听本机的2222号端口 另外一台机器就能连接到这台监听的机器上,假设上面那台机器的ip是192. nc 之后就能互相发送字符了 2. iptux通 ...

  3. xdcms_3.0.1 | 代码审计

    这周的审计任务,这次审计 xdcms . 下面就开始审计之旅.                                                                     ...

  4. 00001 - Linux 上的 Shebang 符号(#!)

    使用Linux或者unix系统的同学可能都对#!这个符号并不陌生,但是你真的了解它吗? 本文了将给你简单介绍一下Shebang(”#!”)这个符号. 首先,这个符号(#!)的名称,叫做”Shebang ...

  5. delphi 获取webbrowser的cookies给Idhttp用

    网上方法一:(可获取,但不完全) 引用mshtml; IHTMLDocument(wb1.Document).cooke; 网上方法二:(获取不到!) 引用winnet,使用InternetGetCo ...

  6. js中的substring

    "ABCDEFG".substring(2,3) 结果为"C"

  7. Windows server 2008 R2充当路由器实现网络的互联

    1.路由器的工作原理 当IP子网中的一台主机发送IP分组给同一IP子网的另一台主机时,它将直接把IP分组送到网络上,对方就能收到.而要送给不同IP子网上的主机时,它要 选择一个能到达目的子网上的路由器 ...

  8. python学习之----获取标签属性

    到目前为止,我们已经介绍过如何获取和过滤标签,以及获取标签里的内容.但是,在网 络数据采集时你经常不需要查找标签的内容,而是需要查找标签属性.比如标签<a> 指向 的URL 链接包含在hr ...

  9. for循环执行时在,每执行一次for循环中弹出提示框,延时问题

    在需求中,ajax的返回值,根据数组内容的长度去做循环,每循环一次弹出提示框,发现for循环的执行速度非常之快,想到了延时,但是在for循环中延时并不能解决这个问题. 查到setTimeout的递归处 ...

  10. mysql 动态拼接表字段,值 mybatis 动态获取表字段

    -- 取表所有字段,自动用逗号分开 select GROUP_CONCAT(DISTINCT COLUMN_NAME) from information_schema.columns where ta ...