Codeforces Round #417 (Div. 2) A. Sagheer and Crossroads 模拟 枚举

Codeforces Round #417 (Div. 2)
A. Sagheer and Crossroads

模拟  枚举

题意 一个红绿灯 按逆时针方向一次给出各个路口的左转,直行,右转,以及行人车道
让你判断,汽车是否有可能撞到行人

注意 当前车道的左转有可能撞到别的车道的行人的

题解 一大堆特判

 1 #include <cstdio>
 2 #include <cmath>
 3 #include <cstdlib>
 4 #include <cstring>
 5 #include <algorithm>
 6 #include <string>
 7 #include <iomanip>
 8 #include <iostream>
 9 using namespace std ;
10
11 int a[5][5] ;
12
13 inline void die()
14 {
15     printf("YES\n") ;
16     exit(0) ;
17 }
18
19 int main()
20 {
21     for(int i=1;i<=4;i++)
22         for(int j=1;j<=4;j++)
23             scanf("%d",&a[ i ][ j ]) ;
24     if(a[ 1 ][ 4 ])
25     {
26         if(a[ 1 ][ 1 ]||a[ 1 ][ 2 ]||a[ 1 ][ 3 ]) die() ;
27         if(a[ 2 ][ 1 ]) die() ;
28         if(a[ 3 ][ 2 ]) die() ;
29         if(a[ 4 ][ 3 ]) die() ;
30     }
31     if(a[ 2 ][ 4 ])
32     {
33         if(a[ 2 ][ 1 ]||a[ 2 ][ 2 ]||a[ 2 ][ 3 ]) die() ;
34         if(a[ 3 ][ 1 ]) die() ;
35         if(a[ 4 ][ 2 ]) die() ;
36         if(a[ 1 ][ 3 ]) die() ;
37     }
38     if(a[ 3 ][ 4 ])
39     {
40         if(a[ 3 ][ 1 ]||a[ 3 ][ 2 ]||a[ 3 ][ 3 ]) die() ;
41         if(a[ 4 ][ 1 ]) die() ;
42         if(a[ 1 ][ 2 ]) die() ;
43         if(a[ 2 ][ 3 ]) die() ;
44     }
45     if(a[ 4 ][ 4 ])
46     {
47         if(a[ 4 ][ 1 ]||a[ 4 ][ 2 ]||a[ 4 ][ 3 ]) die() ;
48         if(a[ 4 ][ 2 ]) die() ;
49         if(a[ 1 ][ 1 ]) die() ;
50         if(a[ 2 ][ 2 ]) die() ;
51         if(a[ 3 ][ 3 ]) die() ;
52     }
53     printf("NO\n") ;
54     return 0 ;
55 }
时间: 2024-08-02 11:04:26

Codeforces Round #417 (Div. 2) A. Sagheer and Crossroads 模拟 枚举的相关文章

Codeforces Round #417 (Div. 2) C. Sagheer and Nubian Market 二分答案 +排序

Codeforces Round #417 (Div. 2) C. Sagheer and Nubian Market 二分答案 +排序 题意 有 a[ i ] 个数 要求选最多的数 使其和不超过 S ,且在此情况下,和最小选最多数情况下 和最小 且 每个数有加成 如果选了 k个数 那么加成后 就是 a[ i ] + k*i ; 题解 二分mid 表示选了个数 加成一下,将加成以后结果排序一下 , 若前 mid数 和大于 s 则此方案不可行 PS 要用 long long ..... 还有 co

Codeforces Round #417 (Div. 2) E. Sagheer and Apple Tree(树上Nim)

题目链接:Codeforces Round #417 (Div. 2) E. Sagheer and Apple Tree 题意: 给你一棵树,每个节点有a[i]个苹果,有两个人要在这个树上玩游戏. 两个人轮流操作,谁不能操作谁就输了. 这个树有一个特性:叶子到根的距离的奇偶性相同. 每次操作可以选一个节点i,和一个数x,x小于当前节点i的苹果数. 对于节点i,如果是叶子节点,就将这x个苹果吃掉. 如果是非叶子节点,就将这x个苹果移向节点i的任意儿子节点. 现在第二个操作的人要交换两个节点的苹果

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

题目链接:Codeforces Round #417 (Div. 2) B. Sagheer, the Hausmeister 题意: 有n层楼,每层有m个房间,每层的两边是楼梯. 现在有一个人站在左下角,这个人必须将这一层的灯关闭后才能去另外一层. 每移动一次需要1分钟,问关闭所有灯需要多少时间. 题解: 考虑DP[i][j]表示当前已经关闭了第i层全部的灯,j=0时表示在这一层的最左边,j=1时表示在这一层的最右边. 然后推上去就行了.最后讨论一下特殊情况. 1 #include<bits/

(博弈\sg) Codeforces Round #417 (Div. 2) E Sagheer and Apple Tree

Sagheer is playing a game with his best friend Soliman. He brought a tree with n nodes numbered from 1 to n and rooted at node 1. The i-th node has ai apples. This tree has a special property: the lengths of all paths from the root to any leaf have t

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

[题意概述] 在一个十字路口 ,给定红绿灯的情况, 按逆时针方向一次给出各个路口的左转,直行,右转,以及行人车道,判断汽车是否有可能撞到行人 [题目分析] 需要在逻辑上清晰,只需要把所有情况列出来即可 [AC] 1 #include<bits/stdc++.h> 2 using namespace std; 3 4 int main() { 5 int light[10][10]; 6 7 8 for(int i = 1; i <= 4; i++) 9 for(int j = 1; j

Codeforces Round #417 (Div. 2)——ABCE

题目链接 题面有点长需耐心读题. A.一个人行道上的人被撞有4种情况 1.所在车道有车驶出 2.右边车道有左转车 3.左边车道有右转车 4.对面车道有直行车 #include <bits/stdc++.h> #define rep(i, j, k) for(int i = j;i <= k;i ++) #define rev(i, j, k) for(int i = j;i >= k;i --) using namespace std; typedef long long ll;

Codeforces Round #256 (Div. 2) B. Suffix Structures(模拟)

题目链接:http://codeforces.com/contest/448/problem/B ---------------------------------------------------------------------------------------------------------------------------------------------------------- 欢迎光临天资小屋:http://user.qzone.qq.com/593830943/ma

Codeforces Round #332 (Div. 2) D. Spongebob and Squares(枚举)

http://codeforces.com/problemset/problem/599/D 题意:给出一个数x,问你有多少个n*m的网格中有x个正方形,输出n和m的值. 思路: 易得公式为:$\sum_{i=0}^{n}(n-i)(m-i) $ 化简得:$\left [ n(n+1)-\frac{n(n+1)}{2}\right ]*m+\frac{n(n+1)(n+2)}{6}-\frac{n(n+1)}{2}*n$ 将n作为小的数,枚举n即可. 1 #include<iostream>

Codeforces Round #354 (Div. 2) B. Pyramid of Glasses (模拟+思维)

原题请戳这里 题意: 将杯子摆成杨辉三角状,即顶层1个杯子,第二层2个杯子,……第N层N个杯子. 每一秒能倒满1个杯子,每次一个杯子满了,酒会平分得流入它下面支撑它的两个杯子中. 如下图所示.1 ≤ n ≤ 10, 0 ≤ t ≤ 10 000. 分析:由于n很小,所以直接模拟此过程,其实也是一个递推的过程. 注意,如果递推的时候没有递推到n+1层,那么最后统计的时候是统计>=1的个数而不是==1的个数, 因为当酒能倒满的杯子大于n层杯子即n*(n+1)/2<t时,递推过程终止于n层,不能向下