A. Okabe and Future Gadget Laboratory
time limit per test

2 seconds

memory limit per test

256 megabytes

input

standard input

output

standard output

Okabe needs to renovate the Future Gadget Laboratory after he tried doing some crazy experiments! The lab is represented as an n by nsquare grid of integers. A good lab is defined as a lab in which every number not equal to 1 can be expressed as the sum of a number in the same row and a number in the same column. In other words, for every x, y such that 1 ≤ x, y ≤ n and ax, y ≠ 1, there should exist two indices s and t so that ax, y = ax, s + at, y, where ai, j denotes the integer in i-th row and j-th column.

Help Okabe determine whether a given lab is good!

Input

The first line of input contains the integer n (1 ≤ n ≤ 50) — the size of the lab.

The next n lines contain n space-separated integers denoting a row of the grid. The j-th integer in the i-th row is ai, j (1 ≤ ai, j ≤ 105).

Output

Print "Yes" if the given lab is good and "No" otherwise.

You can output each letter in upper or lower case.

Examples
input
3
1 1 2
2 3 1
6 4 1
output
Yes
input
3
1 5 2
1 1 1
1 2 3
output
No
Note

In the first sample test, the 6 in the bottom left corner is valid because it is the sum of the 2 above it and the 4 on the right. The same holds for every number not equal to 1 in this table, so the answer is "Yes".

In the second sample test, the 5 cannot be formed as the sum of an integer in the same row and an integer in the same column. Thus the answer is "No".

题意:

懒得说。

思路:

四重循环暴力;

实现代码:

#include<iostream>
using namespace std; int main(){
int m,i,j,k,l,a[][];
cin>>m;
for(i=;i<m;i++){
for(j=;j<m;j++){
cin>>a[i][j];
}
}
int flag = ;
for(i=;i<m;i++){
for(j=;j<m;j++){
if(a[i][j]!=){
flag = ;
for(k=;k<m;k++){
for(l=;l<m;l++){
if(a[i][k]+a[l][j]==a[i][j])
flag = ;
}
}
if(flag==){
cout<<"No"<<endl;
return ;
}
}
}
}
cout<<"Yes"<<endl;
return ; }
B. Okabe and Banana Trees
time limit per test

2 seconds

memory limit per test

256 megabytes

input

standard input

output

standard output

Okabe needs bananas for one of his experiments for some strange reason. So he decides to go to the forest and cut banana trees.

Consider the point (x, y) in the 2D plane such that x and y are integers and 0 ≤ x, y. There is a tree in such a point, and it has x + ybananas. There are no trees nor bananas in other points. Now, Okabe draws a line with equation . Okabe can select a single rectangle with axis aligned sides with all points on or under the line and cut all the trees in all points that are inside or on the border of this rectangle and take their bananas. Okabe's rectangle can be degenerate; that is, it can be a line segment or even a point.

Help Okabe and find the maximum number of bananas he can get if he chooses the rectangle wisely.

Okabe is sure that the answer does not exceed 1018. You can trust him.

Input

The first line of input contains two space-separated integers m and b (1 ≤ m ≤ 1000, 1 ≤ b ≤ 10000).

Output

Print the maximum number of bananas Okabe can get from the trees he cuts.

Examples
input
1 5
output
30
input
2 3
output
25
Note

The graph above corresponds to sample test 1. The optimal rectangle is shown in red and has 30 bananas.

思路:

推公式。

实现代码:

#include<iostream>
using namespace std;
#define ll long long
ll m,b;
ll num(ll x){
ll sum1 = ;
//cout<<"x:"<<x<<endl;
sum1 = (b-x/m)*(b-x/m+)/*(x+)+(b-x/m+)*(+x)*x/;
return sum1;
}
int main(){
ll sum=,maxx,i,j;
cin>>m>>b;
ll k = -m;
ll maxn = -;
while(k<=m*b){
k+=m;
if(num(k)>maxn){
maxn = num(k);
}
}
cout<<maxn<<endl;
return ;
}
C. Okabe and Boxes
time limit per test

3 seconds

memory limit per test

256 megabytes

input

standard input

output

standard output

Okabe and Super Hacker Daru are stacking and removing boxes. There are n boxes numbered from 1 to n. Initially there are no boxes on the stack.

Okabe, being a control freak, gives Daru 2n commands: n of which are to add a box to the top of the stack, and n of which are to remove a box from the top of the stack and throw it in the trash. Okabe wants Daru to throw away the boxes in the order from 1 to n. Of course, this means that it might be impossible for Daru to perform some of Okabe's remove commands, because the required box is not on the top of the stack.

That's why Daru can decide to wait until Okabe looks away and then reorder the boxes in the stack in any way he wants. He can do it at any point of time between Okabe's commands, but he can't add or remove boxes while he does it.

Tell Daru the minimum number of times he needs to reorder the boxes so that he can successfully complete all of Okabe's commands. It is guaranteed that every box is added before it is required to be removed.

Input

The first line of input contains the integer n (1 ≤ n ≤ 3·105) — the number of boxes.

Each of the next 2n lines of input starts with a string "add" or "remove". If the line starts with the "add", an integer x (1 ≤ x ≤ n) follows, indicating that Daru should add the box with number x to the top of the stack.

It is guaranteed that exactly n lines contain "add" operations, all the boxes added are distinct, and n lines contain "remove" operations. It is also guaranteed that a box is always added before it is required to be removed.

Output

Print the minimum number of times Daru needs to reorder the boxes to successfully complete all of Okabe's commands.

Examples
input
3
add 1
remove
add 2
add 3
remove
remove
output
1
input
7
add 3
add 2
add 1
remove
add 4
remove
remove
remove
add 6
add 7
add 5
remove
remove
remove
output
2
Note

In the first sample, Daru should reorder the boxes after adding box 3 to the stack.

In the second sample, Daru should reorder the boxes after adding box 4 and box 7 to the stack.

解题思路:

要按顺序输出1-n,那么当栈顶元素和当前要输出的相同时,直接输出就行,不同时,则需要进行排序操作,默认最优排序使栈中所有元素都可以按指定顺序输出,记一次操作,问需要几次操作。

实现代码:

#include<bits/stdc++.h>
using namespace std;
stack<int>sta;
int main()
{
int m,i,x,ans = ;
int sum = ;
char s[];
scanf("%d",&m);
for(i=;i<m*;i++){
scanf("%s",s);
if(s[]=='a'){
scanf("%d",&x);
sta.push(x);
}
else{
ans ++;
if(sta.empty()==)
continue;
if(sta.top()!=ans){
sum++;
while(sta.empty()==){
sta.pop();}
}
else{
sta.pop();
}
}
}
printf("%d\n",sum);
return ;
}

Codeforces Round #420 (Div. 2) A,B,C的更多相关文章

  1. 【Codeforces Round #420 (Div. 2) C】Okabe and Boxes

    [题目链接]:http://codeforces.com/contest/821/problem/C [题意] 给你2*n个操作; 包括把1..n中的某一个数压入栈顶,以及把栈顶元素弹出; 保证压入和 ...

  2. 【Codeforces Round #420 (Div. 2) B】Okabe and Banana Trees

    [题目链接]:http://codeforces.com/contest/821/problem/B [题意] 当(x,y)这个坐标中,x和y都为整数的时候; 这个坐标上会有x+y根香蕉; 然后给你一 ...

  3. 【Codeforces Round #420 (Div. 2) A】Okabe and Future Gadget Laboratory

    [题目链接]:http://codeforces.com/contest/821/problem/A [题意] 给你一个n*n的数组; 然后问你,是不是每个位置(x,y); 都能找到一个同一行的元素q ...

  4. Codeforces Round #420 (Div. 2) - C

    题目链接:http://codeforces.com/contest/821/problem/C 题意:起初有一个栈,给定2*n个命令,其中n个命令是往栈加入元素,另外n个命令是从栈中取出元素.你可以 ...

  5. Codeforces Round #420 (Div. 2) - E

    题目链接:http://codeforces.com/contest/821/problem/E 题意:起初在(0,0),现在要求走到(k,0),问你存在多少种走法. 其中有n条线段,每条线段为(a, ...

  6. Codeforces Round #420 (Div. 2) - B

    题目链接:http://codeforces.com/contest/821/problem/B 题意:二维每个整点坐标(x,y)拥有的香蕉数量为x+y,现在给你一个直线方程的m和b参数,让你找一个位 ...

  7. Codeforces Round #420 (Div. 2) - A

    题目链接:http://codeforces.com/contest/821/problem/A 题意:给定一个n*n的矩阵. 问你这个矩阵是否满足矩阵里的元素除了1以外,其他元素都可以在该元素的行和 ...

  8. Codeforces Round #420 (Div. 2)

    /*************************************************************************************************** ...

  9. Codeforces Round #420 (Div. 2) E. Okabe and El Psy Kongroo 矩阵快速幂优化dp

    E. Okabe and El Psy Kongroo time limit per test 2 seconds memory limit per test 256 megabytes input ...

随机推荐

  1. 火狐浏览器 system error code 1722 rpc服务器不可用和谷歌浏览器的插件application/x-print-ladop不支持

    今天要实现打印的功能,但是火狐浏览器总是出现提示:火狐浏览器 system error code 1722 rpc服务器不可用 后来发现主要是系统服务中的一个windows服务没有打开导致的. 将wi ...

  2. samba服务,连接远程开发机

    到了新环境,自己的开发机需要通过跳板机连,每次登录跳板机都需要RSA动态密码.一开始让我迷惑的是,这有个跳板机,那怎么让本地代码和开发机代码同步呢.以前公司的情况,一个是不需要跳板机,在phpstor ...

  3. 一个简单的javascript节流器实现

    节流器 javascript的节流器主要用于延缓某些动作的执行,比如ajax请求,如果input框注册了input事件,那么当用户输入时就会持续的触发这个事件,如果回调函数中持续的通过ajax调用后台 ...

  4. Luogu2467 SDOI2010 地精部落 DP

    传送门 一个与相对大小关系相关的$DP$ 设$f_{i,j,0/1}$表示放了$i$个,其中最后一个数字在$i$个中是第$j$大,且最后一个是极大值($1$)或极小值时($0$)的方案数.转移: $$ ...

  5. .NET Core 3.0 跟踪

    Preview1: https://blogs.msdn.microsoft.com/dotnet/2018/12/04/announcing-net-core-3-preview-1-and-ope ...

  6. (转)Xpath语法格式整理

    原文 经常在工作中会使用到XPath的相关知识,但每次总会在一些关键的地方不记得或不太清楚,所以免不了每次总要查一些零碎的知识,感觉即很烦又浪费时间,所以对XPath归纳及总结一下. 在这篇文章中你将 ...

  7. C# 套接字编程:Scoket,我用Scoket做的C# Windows应用程序如下:

    首先请允许我做一个截图: 以上,是我服务端设计 我们知道:服务器端口数最大可以有65535个,但是实际上常用的端口才几十个,由此可以看出未定义的端口相当多.因此,我们可以通过程序随机获取一个当前可用的 ...

  8. 【php增删改查实例】第十五节 - 用户管理模块(删除确认)

    假如有一天,用户找到你,说万一不小心手一抖,就点击了删除用户,不太好.能不能再误点的时候,再给个确认框,让用户进行二次确认. OK,用户是上帝.这边我们可以考虑用confirm方法进行开发. 参考代码 ...

  9. 浅谈js拖拽

    本文来自网易云社区 作者:刘凌阳 前言 本文依据半年前本人的分享<浅谈js拖拽>撰写,算是一篇迟到的文章. 基本思路 虽然现在关于拖拽的组件库到处都是,HTML5也把拖放纳入了标准.但考虑 ...

  10. Linux内核及分析 第四周 扒开系统调用的三层皮(上)

    实验过程 选择20号系统调用getpid(取得进程识别码) 在网上查询getpid函数的C语言代码以及其嵌入式汇编语句 C语言代码: #include <stdio.h> #include ...