Codeforces Round #363 (Div. 2) A-C

A. Launch of Collider

找最近的R和L之间的距离

#include <iostream>
#include <cstring>
#include <cstdio>
#include <algorithm>
#include <queue>
#include <vector>
#include <iomanip>
#include <math.h>
#include <map>
using namespace std;
#define FIN     freopen("input.txt","r",stdin);
#define FOUT    freopen("output.txt","w",stdout);
#define INF     0x3f3f3f3f
#define INFLL   0x3f3f3f3f3f3f3f
#define lson    l,m,rt<<1
#define rson    m+1,r,rt<<1|1
typedef long long LL;
typedef pair<int, int> PII;
using namespace std;

const int maxn = 200000 + 5;

char s[maxn];
int a[maxn];

int main() {
   //FIN
   int n;
   while(~scanf("%d", &n)) {
       scanf("%s", s + 1);
       int ans = INF;
       for(int i = 1; i <= n; i++) scanf("%d", &a[i]);
       int flag = 0;
       for(int i = 1; i <= n; i++) {
           if(flag != 0) {
                if(s[i] == ‘R‘) flag = i;
                else if(s[i] == ‘L‘) ans = min(ans, a[i] - a[flag]);
           }
           else if(s[i] == ‘R‘) flag = i;
           else continue;
       }
       if(ans == INF) printf("-1\n");
       else printf("%d\n", ans/2);

   }
   return 0;
}

  

B. One Bomb

*是墙问可不可以用一个炸弹把所有的墙炸掉

炸弹可以炸当前坐标上x,y轴上的所有点 (就是一个十字

直接在读取数据时维护一个前缀然后再扫一遍判断就可以了

#include <iostream>
#include <cstring>
#include <cstdio>
#include <algorithm>
#include <queue>
#include <vector>
#include <iomanip>
#include <math.h>
#include <map>
using namespace std;
#define FIN     freopen("input.txt","r",stdin);
#define FOUT    freopen("output.txt","w",stdout);
#define INF     0x3f3f3f3f
#define INFLL   0x3f3f3f3f3f3f3f
#define lson    l,m,rt<<1
#define rson    m+1,r,rt<<1|1
typedef long long LL;
typedef pair<int, int> PII;
using namespace std;

const int maxn = 1000 + 5;

int q1[maxn];
int q2[maxn];
char mp[maxn][maxn];

int main() {
   //FIN
   int n, m;
   while(~scanf("%d%d", &n, &m)) {
        int cnt = 0;
        memset(q1, 0, sizeof(q1));
        memset(q2, 0, sizeof(q2));
        for(int i = 0; i < n; i++) {
            for(int j = 0; j < m; j++) {
                cin >> mp[i][j];
                if(mp[i][j] == ‘*‘) {
                    cnt++;
                    q1[i]++;
                    q2[j]++;
                }
            }
        }
        int flag = 0;

        for(int i = 0; i < n; i++) {
            for(int j = 0; j < m; j++) {
                int tmp = cnt;
                if(mp[i][j] == ‘*‘) tmp++;
                if(q1[i] + q2[j] == tmp) {
                    printf("YES\n");
                    printf("%d %d\n", i+1, j+1);
                    flag = 1;
                    break;
                }
            }
            if(flag) break;
        }
        if(flag == 0) printf("NO\n");

   }

   return 0;
}

  

C. Vacations

1 2 代表两种活动 3表示两种活动都可以进行 0是休息 不可以连续两天进行同一个活动,问最少休息的天数是多少, 贪心

#include <iostream>
#include <cstring>
#include <cstdio>
#include <algorithm>
#include <queue>
#include <vector>
#include <iomanip>
#include <math.h>
#include <map>
using namespace std;
#define FIN     freopen("input.txt","r",stdin);
#define FOUT    freopen("output.txt","w",stdout);
#define INF     0x3f3f3f3f
#define INFLL   0x3f3f3f3f3f3f3f
#define lson    l,m,rt<<1
#define rson    m+1,r,rt<<1|1
typedef long long LL;
typedef pair<int, int> PII;
using namespace std;

const int maxn = 100 + 5;

int a[maxn];

int main() {
   //FIN
   int n;
   while(~scanf("%d", &n)) {
       for(int i = 1; i <= n; i++) scanf("%d", &a[i]);
       int flag = -1;
       int ans = 0;
       for(int i = 1; i <= n; i++) {
            if(a[i] == 0) ans++, flag = -1;
            else if(a[i] == 1) {
                if(flag != 1) flag = 1;
                else flag = -1, ans++;
            }
            else if(a[i] == 2) {
                if(flag != 2) flag = 2;
                else flag = -1, ans++;
            }
            else {
                if(flag == 1) flag = 2;
                else if(flag == 2) flag = 1;
                //else if(a[i+1] == 1) flag = 2;
                //else flag = 1;
            }
       }
       printf("%d\n", ans);

   }
   return 0;
}

  

时间: 2024-11-25 12:37:34

Codeforces Round #363 (Div. 2) A-C的相关文章

Codeforces Round #363 (Div. 2)

A. Launch of Collider 根据字符左移或右移,输出第一次碰撞的位置,不然输出-1 1 #include <cstdio> 2 #include <iostream> 3 #include <cstring> 4 #include <algorithm> 5 using namespace std; 6 #define LL long long 7 char ch[200005]; 8 LL a[200005],ans; 9 int n; 1

CodeForces 698A - Vacations (Codeforces Round #363 (Div. 2))

要么去体育馆,要么去比赛,要么闲在家里 给出每一天体育馆和比赛的有无情况,要求连续两天不能去同一个地方 问最少闲几天 DP方程很容易看出 dp(第i天能去的地方) = min(dp(第i-1天的三种情况)) : dp(第i天呆在家里) = min(dp(第i-1天的三种情况))+1: 1 #include <cstdio> 2 #include <iostream> 3 using namespace std; 4 #define inf 0x3f3f3f3f 5 int a[10

Codeforces Round #363 Div.2[11110]

好久没做手生了,不然前四道都是能A的,当然,正常发挥也是菜. A:Launch of Collider 题意:20万个点排在一条直线上,其坐标均为偶数.从某一时刻开始向左或向右运动,速度为每秒1个单位长度.输入给出每个点的坐标及其移动的方向,求发生第一次碰撞的时间,若不会碰撞,则输出-1 最先发生碰撞的是一定是初始时相邻的两个点,因此只需对每个点循环一边,判断其是否会与下一个点碰撞,并求出其时间即可. #include<stdio.h> #include<stdlib.h> int

Codeforces Round #363 (Div. 1) C. LRU

题意: n个数,长度为k的缓存,每次询问,每个数以pi的概率被选,如果不在缓存区则加入,如果缓存区满了,则第一个进缓存的出来,问10^100次询问以后每个数在缓存的概率 思路: 状压DP,看了hzwer的代码 f[x]表示当前状态为x的概率 枚举不在缓存区的数:f[t]+=f[x]*(p[i]/tot);  t=x|(1<<(i-1)); tot是当前状态情况下,不在缓存区的所有概率 如果缓存区数大于k,则当前状态概率为0 1 // #pragma comment(linker, "

Codeforces Round #363 (Div. 2)A-D

699A 题意:在一根数轴上有n个东西以相同的速率1m/s在运动,给出他们的坐标以及运动方向,问最快发生的碰撞在什么时候 思路:遍历一遍坐标,看那两个相邻的可能相撞,更新ans #include<cstdio> int n,num[200100]; char s[200100]; int main() { scanf("%d",&n); scanf("%s",s+1); for(int i=1;i<=n;i++) scanf("%

Codeforces Round #363 (Div. 2) C

Description Vasya has n days of vacations! So he decided to improve his IT skills and do sport. Vasya knows the following information about each of this ndays: whether that gym opened and whether a contest was carried out in the Internet on that day.

Codeforces Round #363 (Div. 2) B 暴力

Description You are given a description of a depot. It is a rectangular checkered field of n × m size. Each cell in a field can be empty (".") or it can be occupied by a wall ("*"). You have one bomb. If you lay the bomb at the cell (x

Codeforces Round #363 (Div. 2) A 水

Description There will be a launch of a new, powerful and unusual collider very soon, which located along a straight line. n particles will be launched inside it. All of them are located in a straight line and there can not be two or more particles l

Codeforces Round #363 (Div. 2) C dp或贪心 两种方法

Description Vasya has n days of vacations! So he decided to improve his IT skills and do sport. Vasya knows the following information about each of this n days: whether that gym opened and whether a contest was carried out in the Internet on that day