Codeforces Round #292 (Div. 2)

换了新ID,以前的ID 运气不好

D:题目隐藏的很深啊!如果说拓扑排序肯定会写,模型转换。

计算每个点‘.‘的度,度:周围4个点为‘.‘的数目。

然后BFS 枚举度为1的点 ,一遍构造,链接的点就度--;

再压入队列中

当枚举的点数不够‘.‘数目时,答案就是‘unique‘;

题目没要你输出any 这本身有蹊跷。

#include <stdio.h>
#include <string.h>
#include <iostream>
#include <algorithm>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <string>
#include <math.h>
#include <stdlib.h>
#include <time.h>
#include<string>
using namespace std;
#define N 2222
#define pii pair<int,int>
#define mp make_pair

int du[N][N];
char f[2][5]={"^<v>","v>^<"};

int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};
char s[N][N];

int cal(int i,int j)
{
    int ans=0;
    ans+=(s[i][j-1]==‘.‘);
    ans+=(s[i][j+1]==‘.‘);
    ans+=(s[i+1][j]==‘.‘);
    ans+=(s[i-1][j]==‘.‘);
    return ans;
}

int main()
{
    int n,m;
    cin>>n>>m;
    for (int i=1;i<=n;i++)
    scanf("%s",s[i]+1);
    queue<pii> Q;
    int cnt=0;
    for (int i=1;i<=n;i++)
    for (int j=1;j<=m;j++)
    if (s[i][j]==‘.‘)
    {
        cnt++;
        du[i][j]=cal(i,j);
        if (du[i][j]==1) Q.push(mp(i,j));
    }

    if (cnt&1)
    {
        puts("Not unique");
        return 0;
    }

    while (!Q.empty())
    {
        pii cur=Q.front();
        Q.pop();
        int x=cur.first;
        int y=cur.second;
        if (s[x][y]==‘.‘)
        {
            int i;
            int xx,yy;
            for (i=0;i<4;i++)
            {
                xx=x+dx[i];
                yy=y+dy[i];
                if (s[xx][yy]==‘.‘) break;
            }
            if (i==4)
            {
                 puts("Not unique");
                 return 0;
            }

            s[x][y]=f[0][i];
            s[xx][yy]=f[1][i];
            du[x][y]=du[xx][yy]=0;
            cnt-=2;
            for (int i=0;i<4;i++)
            {
                int nx=xx+dx[i];
                int ny=yy+dy[i];
                if (s[nx][ny]==‘.‘)
                {
                    du[nx][ny]--;
                    if (du[nx][ny]==1) Q.push(mp(nx,ny));
                }
            }
        }
    }

    if (cnt!=0) puts("Not unique");
    else for (int i=1;i<=n;i++)
        printf("%s\n",s[i]+1);

    return 0;
}

C:一眼贪心题;

做法就是拆数,比如8的话就拆成2*2*2;

9的话是9!,也就是3*3*2^4;

然后比如有一个7 那么6,5,4,3,2,1的数目依次-1;

  1 #include<stdio.h>
  2 #include<string>
  3 #include<iostream>
  4 #include<queue>
  5 #include<cmath>
  6 #include<string.h>
  7 #include <vector>
  8 #include<map>
  9 #include<stack>
 10 using namespace std;
 11 typedef long long ll;
 12
 13 string s;
 14 int b[33333];
 15 int c[333333];
 16
 17 int main()
 18 {
 19      int n;
 20      cin>>n;
 21      cin>>s;
 22      int p=0;
 23      while (s[p]==‘0‘&&p<s.size()) p++;
 24      for (p;p<n;p++)
 25      {
 26          if (s[p]==‘9‘) {
 27                       b[3]+=2;
 28                       b[2]+=3;
 29          for (int i=7;i>=2;i--) b[i]++;
 30          }
 31          else if (s[p]==‘8‘)
 32          {
 33              b[2]+=3;
 34              for (int i=7;i>=2;i--) b[i]++;
 35          }
 36
 37          else if (s[p]==‘7‘)
 38          {
 39              for (int i=7;i>=2;i--) b[i]++;
 40          }
 41          else if (s[p]==‘6‘) for (int i=6;i>=2;i--) b[i]++;
 42          else if (s[p]==‘5‘) for (int i=5;i>=2;i--) b[i]++;
 43          else if (s[p]==‘4‘) for (int i=4;i>=2;i--) b[i]++;
 44          else if (s[p]==‘3‘) for (int i=3;i>=2;i--) b[i]++;
 45          else if (s[p]==‘2‘) b[2]++;
 46      }
 47
 48      while (b[7])
 49      {
 50          c[7]++;
 51          b[7]--;
 52
 53          for (int i=6;i>=2;i--)
 54          {
 55              //c[i]++;
 56              b[i]--;
 57          }
 58      }
 59      while (b[6])
 60      {
 61          b[6]--;
 62          b[2]++;
 63          b[3]++;
 64      }
 65
 66      while (b[5])
 67      {
 68          c[5]++;
 69          b[5]--;
 70          for (int i=4;i>=2;i--)
 71          {
 72              //c[i]++;
 73              b[i]--;
 74          }
 75      }
 76
 77      while (b[4])
 78      {
 79          b[4]--;
 80          b[2]+=2;
 81      }
 82
 83     while (b[3])
 84      {
 85          c[3]++;
 86          b[3]--;
 87         // c[2]++;
 88          b[2]--;
 89      }
 90
 91      while (b[2])
 92      {
 93          c[2]++;
 94          b[2]--;
 95
 96      }
 97      for (int i=9;i>=2;i--)
 98      while (c[i])
 99      {
100          cout<<i;
101          c[i]--;
102      }
103      return 0;
104 }

B:无限暴力下就好了

 1 #include<stdio.h>
 2 #include<string>
 3 #include<iostream>
 4 #include<queue>
 5 #include<cmath>
 6 #include<string.h>
 7 #include <vector>
 8 #include<map>
 9 #include<stack>
10 using namespace std;
11 typedef long long ll;
12
13 int a[123],b[123];
14 int main()
15 {
16
17     int n,m;
18     cin>>n>>m;
19     int nn;
20     int mm;
21     cin>>nn;
22     int x;
23     for (int i=1;i<=nn;i++) cin>>x,a[x]=1;
24     cin>>mm;
25     for (int i=1;i<=mm;i++) cin>>x,b[x]=1;
26
27     int ans=nn+mm;
28     int t=0;
29     while (t<3000000)
30     {
31         t++;
32         if (ans==n+m)
33         {
34             cout<<"Yes";
35             return 0;
36         }
37         if (!a[t%n]&&b[t%m])
38         {
39             ans++;
40             a[t%n]=1;
41         }
42         else if (a[t%n]&&!b[t%m])
43         {
44             ans++;
45             b[t%m]=1;
46         }
47     }
48      cout<<"No";
49      return 0;
50 }

20

时间: 2024-12-28 01:33:57

Codeforces Round #292 (Div. 2)的相关文章

Codeforces Round #292 (Div. 1) B. Drazil and Tiles(拓扑排序)

题目地址:codeforces 292 B 用队列维护度数为1的点,也就是可以唯一确定的点,然后每次找v1,v2,并用v2来更新与之相连的点,如果更新后的点度数为1,就加入队列.若最后还有为"."的,说明无解或解不唯一. 代码如下: #include <iostream> #include <string.h> #include <math.h> #include <queue> #include <algorithm> #i

Codeforces Round #292 (Div. 1) B. Drazil and Tiles (类似拓扑)

题目链接:http://codeforces.com/problemset/problem/516/B 一个n*m的方格,'*'不能填.给你很多个1*2的尖括号,问你是否能用唯一填法填满方格. 类似topsort,'.'与上下左右的'.',的相连.从度为1的点作为突破口. 1 //#pragma comment(linker, "/STACK:102400000, 102400000") 2 #include <algorithm> 3 #include <iostr

Codeforces Round #292 (Div. 2 Div. 1)

比赛链接:http://codeforces.com/contest/515  http://codeforces.com/contest/516 A. Drazil and Date time limit per test 1 second memory limit per test 256 megabytes Someday, Drazil wanted to go on date with Varda. Drazil and Varda live on Cartesian plane. D

Codeforces Round #292 (Div. 2) D. Drazil and Tiles [拓扑排序 dfs]

传送门 D. Drazil and Tiles time limit per test 2 seconds memory limit per test 256 megabytes Drazil created a following problem about putting 1 × 2 tiles into an n × m grid: "There is a grid with some cells that are empty and some cells that are occupie

Codeforces Round #292 (Div. 2) -- D. Drazil and Tiles (拓扑排序)

D. Drazil and Tiles time limit per test 2 seconds memory limit per test 256 megabytes input standard input output standard output Drazil created a following problem about putting 1?×?2 tiles into an n?×?m grid: "There is a grid with some cells that a

Codeforces Round #292 (Div. 1)---A. Drazil and Factorial

Drazil is playing a math game with Varda. Let's define for positive integer x as a product of factorials of its digits. For example, . First, they choose a decimal number a consisting of n digits that contains at least one digit larger than 1. This n

Codeforces Round #292 (Div. 1) - B. Drazil and Tiles

B. Drazil and Tiles Drazil created a following problem about putting 1 × 2 tiles into an n × m grid: "There is a grid with some cells that are empty and some cells that are occupied. You should use 1 × 2 tiles to cover all empty cells and no two tile

Codeforces Round #292 (Div. 2) -- B. Drazil and His Happy Friends

B. Drazil and His Happy Friends time limit per test 2 seconds memory limit per test 256 megabytes input standard input output standard output Drazil has many friends. Some of them are happy and some of them are unhappy. Drazil wants to make all his f

Codeforces Round #292 (Div. 1)

A 简单题 B 用1*2的砖块铺满所有的点 方案数是否唯一 消去度数为1的 直到不能消为止 还有点就是无解或者不唯一 C 求任意两个端点u,v, 2 * h[u] + 2 * h[v] + d[u] + d[u+1] + ... +d[v]的最大值 转换 a[i] = 2*h[i]+(d[1]+d[2]+...+d[i]) b[i]= 2*h[i]-(d[1]+d[2]+...+d[i]) 所求变成a[u]+b[v]的最大值并且 u > v 其实不用考虑u < v的情况 要考虑u != v的情