A. Sagheer and Crossroads
time limit per test

1 second

memory limit per test

256 megabytes

input

standard input

output

standard output

Sagheer is walking in the street when he comes to an intersection of two roads. Each road can be represented as two parts where each part has 3 lanes getting into the intersection (one for each direction) and 3 lanes getting out of the intersection, so we have 4 parts in total. Each part has 4 lights, one for each lane getting into the intersection (l — left, s — straight, r — right) and a light p for a pedestrian crossing.

An accident is possible if a car can hit a pedestrian. This can happen if the light of a pedestrian crossing of some part and the light of a lane that can get to or from that same part are green at the same time.

Now, Sagheer is monitoring the configuration of the traffic lights. Your task is to help him detect whether an accident is possible.

Input

The input consists of four lines with each line describing a road part given in a counter-clockwise order.

Each line contains four integers lsrp — for the left, straight, right and pedestrian lights, respectively. The possible values are 0 for red light and 1 for green light.

Output

On a single line, print "YES" if an accident is possible, and "NO" otherwise.

Examples
input
1 0 0 1
0 1 0 0
0 0 1 0
0 0 0 1
output
YES
input
0 1 1 0
1 0 1 0
1 1 0 0
0 0 0 1
output
NO
input
1 0 0 0
0 0 0 1
0 0 0 0
1 0 1 0
output
NO
Note

In the first example, some accidents are possible because cars of part 1 can hit pedestrians of parts 1 and 4. Also, cars of parts 2 and 3 can hit pedestrians of part 4.

In the second example, no car can pass the pedestrian crossing of part 4 which is the only green pedestrian light. So, no accident can occur.

这把自己被花式吊打了,比较傻,静纠结些没用的,下次自己还是好好看题好了,A是行人被撞检测,行人要想不被撞,这一侧一定没有任何车通过,左侧的也没有右转,右侧的也没有左转,对面的也没有向前开的,这个分析好就行,我本来还在纠结车撞的问题,完全就是答非所问,自己还1wa,因为自己之前手贱改了变量,那样第四个路口就没有了

#include <bits/stdc++.h>
using namespace std;
int main() {
ios::sync_with_stdio(false);
cin.tie();
int f=;
int a[][];
for(int i=;i<;i++)
for(int j=;j<=;j++)
cin>>a[i][j];
for(int i=;i<;i++){
if(a[i][]&&(a[i][]||a[i][]||a[i][]||a[(i+)%][]||a[(i+)%][]||a[(i+)%][]))
f=;
}
if(f)
printf("YES");
else
printf("NO"); return ;
}
C. Sagheer and Nubian Market
time limit per test

2 seconds

memory limit per test

256 megabytes

input

standard input

output

standard output

On his trip to Luxor and Aswan, Sagheer went to a Nubian market to buy some souvenirs for his friends and relatives. The market has some strange rules. It contains n different items numbered from 1 to n. The i-th item has base cost ai Egyptian pounds. If Sagheer buys k items with indices x1, x2, ..., xk, then the cost of item xj is axj + xj·k for 1 ≤ j ≤ k. In other words, the cost of an item is equal to its base cost in addition to its index multiplied by the factor k.

Sagheer wants to buy as many souvenirs as possible without paying more than S Egyptian pounds. Note that he cannot buy a souvenir more than once. If there are many ways to maximize the number of souvenirs, he will choose the way that will minimize the total cost. Can you help him with this task?

Input

The first line contains two integers n and S (1 ≤ n ≤ 105 and 1 ≤ S ≤ 109) — the number of souvenirs in the market and Sagheer's budget.

The second line contains n space-separated integers a1, a2, ..., an (1 ≤ ai ≤ 105) — the base costs of the souvenirs.

Output

On a single line, print two integers kT — the maximum number of souvenirs Sagheer can buy and the minimum total cost to buy these k souvenirs.

Examples
input
3 11
2 3 5
output
2 11
input
4 100
1 2 5 6
output
4 54
input
1 7
7
output
0 0
Note

In the first example, he cannot take the three items because they will cost him [5, 9, 14] with total cost 28. If he decides to take only two items, then the costs will be [4, 7, 11]. So he can afford the first and second items.

In the second example, he can buy all items as they will cost him [5, 10, 17, 22].

In the third example, there is only one souvenir in the market which will cost him 8 pounds, so he cannot buy it.

这个题就属于自己没有看懂的吧,人家现在是有顺序的了,要进行+xj·k,我还以为是选择一些数进行操作,没读懂题,挺可怕的。因为wa,假如TLE自己肯定就去手撕二分了,二分并不难。

#include<bits/stdc++.h>
using namespace std;
long long n,s,i,l,r,mid,f[],a[],sum,ans1,ans2;
int main()
{
cin>>n>>s;
for(i=;i<=n;i++)
cin>>f[i];
l=;r=n;
while(l<r)
{
mid=(l+r)/+;
for(i=;i<=n;i++)
a[i]=f[i]+i*mid;
sort(a+,a++n);
sum=;
for(i=;i<=mid;i++)
sum+=a[i];
if(sum>s)
r=mid-;
else
{
if(mid>ans1)
ans1=mid,ans2=sum;
l=mid;
}
}
cout<<ans1<<' '<<ans2;
return ;
}
B. Sagheer, the Hausmeister
time limit per test

1 second

memory limit per test

256 megabytes

input

standard input

output

standard output

Some people leave the lights at their workplaces on when they leave that is a waste of resources. As a hausmeister of DHBW, Sagheer waits till all students and professors leave the university building, then goes and turns all the lights off.

The building consists of n floors with stairs at the left and the right sides. Each floor has m rooms on the same line with a corridor that connects the left and right stairs passing by all the rooms. In other words, the building can be represented as a rectangle with n rows and m + 2 columns, where the first and the last columns represent the stairs, and the m columns in the middle represent rooms.

Sagheer is standing at the ground floor at the left stairs. He wants to turn all the lights off in such a way that he will not go upstairs until all lights in the floor he is standing at are off. Of course, Sagheer must visit a room to turn the light there off. It takes one minute for Sagheer to go to the next floor using stairs or to move from the current room/stairs to a neighboring room/stairs on the same floor. It takes no time for him to switch the light off in the room he is currently standing in. Help Sagheer find the minimum total time to turn off all the lights.

Note that Sagheer does not have to go back to his starting position, and he does not have to visit rooms where the light is already switched off.

Input

The first line contains two integers n and m (1 ≤ n ≤ 15 and 1 ≤ m ≤ 100) — the number of floors and the number of rooms in each floor, respectively.

The next n lines contains the building description. Each line contains a binary string of length m + 2 representing a floor (the left stairs, then m rooms, then the right stairs) where 0 indicates that the light is off and 1 indicates that the light is on. The floors are listed from top to bottom, so that the last line represents the ground floor.

The first and last characters of each string represent the left and the right stairs, respectively, so they are always 0.

Output

Print a single integer — the minimum total time needed to turn off all the lights.

Examples
input
2 2
0010
0100
output
5
input
3 4
001000
000010
000010
output
12
input
4 3
01110
01110
01110
01110
output
18
Note

In the first example, Sagheer will go to room 1 in the ground floor, then he will go to room 2 in the second floor using the left or right stairs.

In the second example, he will go to the fourth room in the ground floor, use right stairs, go to the fourth room in the second floor, use right stairs again, then go to the second room in the last floor.

In the third example, he will walk through the whole corridor alternating between the left and right stairs at each floor.

左右两边都有楼梯,第一次必须从左边楼梯上去,他要上去关灯,也许不用上去,找到最小的他走的路,直接dp一下,分左右上去的情况

#include<bits/stdc++.h>
using namespace std;
string light[];
int f[][];
int mi[],ma[];
int w,h;
int main() {
cin>>h>>w;
for(int i=h; i>; i--) {
cin>>light[i];
mi[i]=w+;
ma[i]=;
for(int j=; j<=w; j++)
if(light[i][j]=='') {
mi[i]=min(mi[i],j);
ma[i]=max(ma[i],j);
}
}
f[][]=;
f[][]=<<;
while(ma[h]==&&mi[h]==w+&&h>)
h--;
for(int i=; i<h; i++) {
f[i][]=f[i-][]+ma[i]*+;
f[i][]=min(f[i][],f[i-][]+w+);
f[i][]=f[i-][]+(w+-mi[i])*+;
f[i][]=min(f[i][],f[i-][]+w+);
}
cout<<min(f[h-][]+ma[h],f[h-][]+(w+-mi[h]))<<endl;

Codeforces Round #417 (Div. 2) 花式被虐的更多相关文章

  1. Codeforces Round #417 (Div. 2) D. Sagheer and Kindergarten(树中判祖先)

    http://codeforces.com/contest/812/problem/D 题意: 现在有n个孩子,m个玩具,每次输入x y,表示x孩子想要y玩具,如果y玩具没人玩,那么x就可以去玩,如果 ...

  2. Codeforces Round #417 (Div. 2) B. Sagheer, the Hausmeister

    http://codeforces.com/contest/812/problem/B 题意: 有n层楼,每层楼有m个房间,1表示灯开着,0表示灯关了.最两侧的是楼梯. 现在每从一个房间移动到另一个房 ...

  3. Codeforces Round #417 (Div. 2) B. Sagheer, the Hausmeister —— DP

    题目链接:http://codeforces.com/problemset/problem/812/B B. Sagheer, the Hausmeister time limit per test ...

  4. [Codeforces Round#417 Div.2]

    来自FallDream的博客,未经允许,请勿转载,谢谢. 有毒的一场div2 找了个1300的小号,结果B题题目看错没交  D题题目剧毒 E题差了10秒钟没交上去. 233 ------- A.Sag ...

  5. Codeforces Round #417 (Div. 2)-A. Sagheer and Crossroad

    [题意概述] 在一个十字路口 ,给定红绿灯的情况, 按逆时针方向一次给出各个路口的左转,直行,右转,以及行人车道,判断汽车是否有可能撞到行人 [题目分析] 需要在逻辑上清晰,只需要把所有情况列出来即可 ...

  6. Codeforces Round #417 (Div. 2) C. Sagheer and Nubian Market

    time limit per test 2 seconds memory limit per test 256 megabytes input standard input output standa ...

  7. Codeforces Round #417 (Div. 2)A B C E 模拟 枚举 二分 阶梯博弈

    A. Sagheer and Crossroads time limit per test 1 second memory limit per test 256 megabytes input sta ...

  8. 【二分】Codeforces Round #417 (Div. 2) C. Sagheer and Nubian Market

    傻逼二分 #include<cstdio> #include<algorithm> using namespace std; typedef long long ll; ll ...

  9. 【动态规划】Codeforces Round #417 (Div. 2) B. Sagheer, the Hausmeister

    预处理每一层最左侧的1的位置,以及最右侧的1的位置. f(i,0)表示第i层,从左侧上来的最小值.f(i,1)表示从右侧上来. 转移方程请看代码. #include<cstdio> #in ...

随机推荐

  1. npm scripts 常用规范总结

    npm scripts 常用规范总结 随着 npm scripts 使用越来越多,需要规范一下, npm run 的使用词. 定义 我定义如下形式: npm run <action>:&l ...

  2. 浏览器详谈及其内部工作机制 —— web开发必读

    浏览器介绍 如今,浏览器格局基本上是五分天下,分别是:IE.Firefox.Safari.Chrome.Opera,而浏览器引擎就更加集中了,主要是四大巨头:IE的浏览器排版引擎Trident,目前随 ...

  3. 安装ubuntu虚拟环境

    一. 安装 1. 准备: 1). Oracle VM VirtualBox https://www.virtualbox.org/ 2). Ubuntu 18.04.2 LTS https://ubu ...

  4. [转+补]Android打包so后魅族5中安装运行崩溃问题的解决方法

    上周在做噪音检测so集成中,遇到不同的so库打包到 APK 时,安装在某些机器上,出现 java.lang.UnsatisfiedLinkError 加载失败. 为此,深究了一下原理,和给出了解决方案 ...

  5. Jquery AJAX使用踩坑小记

    在使用jquery ajax时,如果其参数是一个json对象,将此参数使用$('#dd').data(param)绑定到一个元素上, 在使用$('#dd').bind('click',function ...

  6. Sublime Text 3 使用小记

    快捷键: [ // 代码对齐插件 { "keys": ["shift+alt+a"], "command": "alignment ...

  7. svn亲笔操作

    1. 创建版本库 [root@iZ28dftuhfaZ db]# svnadmin create /var/svn-repositories/app-api/ . 导入数据到你的版本库[root@iZ ...

  8. js 分组数组

    思路: 1.先将数组按照一定规则排序: 2.再拆分数组到Map中,按Key分类: 3.再从Map中遍历取出要显示的内容: sortBroadList: function (broadcastList) ...

  9. Codeforces Round #316 (Div. 2) B Simple Game 贪心

    贪心,如果m分成的两个区间长度不相等,那么选长的那个区间最接近m的位置,否则选m-1位置,特判一下n等于1的情况 #include<bits/stdc++.h> using namespa ...

  10. vue 中 $set 的使用

    在我们使用vue进行开发的过程中,可能会遇到一种情况:当生成vue实例后,当再次给数据赋值时,有时候并不会自动更新到视图上去: <!DOCTYPE html> <html> & ...