Codeforces Round #420 (Div. 2) A,B,C
2 seconds
256 megabytes
standard input
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!
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).
Print "Yes" if the given lab is good and "No" otherwise.
You can output each letter in upper or lower case.
3
1 1 2
2 3 1
6 4 1
Yes
3
1 5 2
1 1 1
1 2 3
No
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 ; }
2 seconds
256 megabytes
standard input
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.
The first line of input contains two space-separated integers m and b (1 ≤ m ≤ 1000, 1 ≤ b ≤ 10000).
Print the maximum number of bananas Okabe can get from the trees he cuts.
1 5
30
2 3
25

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 ;
}
3 seconds
256 megabytes
standard input
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.
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.
Print the minimum number of times Daru needs to reorder the boxes to successfully complete all of Okabe's commands.
3
add 1
remove
add 2
add 3
remove
remove
1
7
add 3
add 2
add 1
remove
add 4
remove
remove
remove
add 6
add 7
add 5
remove
remove
remove
2
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的更多相关文章
- 【Codeforces Round #420 (Div. 2) C】Okabe and Boxes
		
[题目链接]:http://codeforces.com/contest/821/problem/C [题意] 给你2*n个操作; 包括把1..n中的某一个数压入栈顶,以及把栈顶元素弹出; 保证压入和 ...
 - 【Codeforces Round #420 (Div. 2) B】Okabe and Banana Trees
		
[题目链接]:http://codeforces.com/contest/821/problem/B [题意] 当(x,y)这个坐标中,x和y都为整数的时候; 这个坐标上会有x+y根香蕉; 然后给你一 ...
 - 【Codeforces Round #420 (Div. 2) A】Okabe and Future Gadget Laboratory
		
[题目链接]:http://codeforces.com/contest/821/problem/A [题意] 给你一个n*n的数组; 然后问你,是不是每个位置(x,y); 都能找到一个同一行的元素q ...
 - Codeforces Round #420 (Div. 2) - C
		
题目链接:http://codeforces.com/contest/821/problem/C 题意:起初有一个栈,给定2*n个命令,其中n个命令是往栈加入元素,另外n个命令是从栈中取出元素.你可以 ...
 - Codeforces Round #420 (Div. 2) - E
		
题目链接:http://codeforces.com/contest/821/problem/E 题意:起初在(0,0),现在要求走到(k,0),问你存在多少种走法. 其中有n条线段,每条线段为(a, ...
 - Codeforces Round #420 (Div. 2) - B
		
题目链接:http://codeforces.com/contest/821/problem/B 题意:二维每个整点坐标(x,y)拥有的香蕉数量为x+y,现在给你一个直线方程的m和b参数,让你找一个位 ...
 - Codeforces Round #420 (Div. 2) - A
		
题目链接:http://codeforces.com/contest/821/problem/A 题意:给定一个n*n的矩阵. 问你这个矩阵是否满足矩阵里的元素除了1以外,其他元素都可以在该元素的行和 ...
 - Codeforces Round #420 (Div. 2)
		
/*************************************************************************************************** ...
 - 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 ...
 
随机推荐
- 生成、查看文件的MD5、SHA、SHA256值
			
生成文件的MD5.SHA.SHA256 Linux系统生成MD5.SHA.SHA256 md5sum file1.zip >> MD5.txt sha1sum file1.zip > ...
 - Luogu  P1439 【模板】最长公共子序列
			
又是模板题呵,但这次的难度有点增加. 先看题目第一个想到DP的经典算法,要O(n^2),然后想其它的算法. 其实我们衢州市一次联考有一题很像这题,不过还要难一点. 思想是离散化+最长不下降子序列(在这 ...
 - LNMP 1.x升级到LNMP 1.4教程及注意事项和多PHP版本使用教程
			
LNMP 1.x版本基本都可以正常升级到1.4使用1.4的管理脚本和新的功能. 升级管理脚本:wget -c http://soft.vpser.net/lnmp/lnmp1.4.tar.gz &am ...
 - Nancy异步用法
			
个人笔记,记录Nancy异步用法 基类,所有请求都将首先执行该类,并执行Before事件 namespace CxyAdvert.Base { public class BaseNancyModel ...
 - MySQL主主同步配置
			
1. MySQL主主配置过程 在上一篇实现了主从同步的基础上,进行主主同步的配置. 这里用node19(主),node20(从)做修改,使得node19和node20变为主主同步配置模式 修改配置文件 ...
 - 大话重构连载15:采用Mock技术完成测试
			
第五次重构我们引入了数据库的设计,用户信息要从数据库中读取,问候语库存储在数据库中,并支持添加与更新.数据库的引入使自动化测试变得困难了,因为数据状态总是变化着的,而这种变化使得测试过程不能复现,这是 ...
 - vs2017+opencv4.0.1安装配置详解(win10)
			
一.说明 笔者之前已经安装过了vs2017,对应的opencv是3.4.0版本的.但现在想体验下opencv4的改变之处,所以下载了最新的opencv4.0.1. vs2017的安装请自行搜索安装,本 ...
 - Ubuntu16.04下安装QQ的完整操作记录(经验证可用)
			
本机安装了Ubuntu16.04系统,用于日常运维办公.打算在Ubuntu上安装QQ,如下操作记录也使用于Ubuntu18.04: 1)先下载特制的QQ程序包(其实就是基于Wine容器做了一些封装,程 ...
 - Java开发23种设计模式之禅
			
六大原则 23种设计模式: 总体来说设计模式分为三大类: *创建型模式,共五种:工厂方法模式.抽象工厂模式.单例模式.建造者模式.原型模式. *结构型模式,共七种:适配器模式.装饰器模式.代理模式.外 ...
 - Java读取oracle数据库中blob字段数据文件保存到本地文件(转载)
			
转自:https://www.cnblogs.com/forever2698/p/4747349.html package com.bo.test; import java.io.FileOutput ...