usaco-4.4-frameup-passed

这个好像要容易些。

/*
ID: qq104801
LANG: C++
TASK: frameup
QQ:104804687
*/

#include <iostream>
#include <fstream>
#include <cstring>
#include <vector>
#include <queue>
#include <stack>
#include <algorithm>

#define rep(i, n) for(int i = 1; i <= n;i++)

using namespace std;

const int maxn=50;

int w,h,p,l[maxn],r[maxn],u[maxn],d[maxn],D[maxn];
char map[maxn][maxn],_p[maxn];
bool a[maxn],g[maxn][maxn];

void dfs()
{
  bool flag=0;
  for(int i=1;i<=26;i++)
    if(a[i])
    {
      flag=1;
      break;
    }
  if(!flag)
  {
    for(int i=1;i<=p;i++)
      cout<<_p[i];
    cout<<endl;
    return;
  }
  for(int i=1;i<=26;i++)
    if(a[i] && D[i]==0)
    {
      _p[++p]=i+‘@‘;
      for(int j=1;j<=26;j++)
        if(g[i][j])
          D[j]--;
      a[i]=0;
      dfs();
      for(int j=1;j<=26;j++)
        if(g[i][j])
          D[j]++;
      a[i]=1;
      p--;
    }
}

void test()
{
    freopen("frameup.in","r",stdin);
    freopen("frameup.out","w",stdout);
    cin>>h>>w;
    char c;
    for(int i=1;i<=h;i++)
      for(int j=1;j<=w;j++)
      {
        cin>>c;
        map[i][j]=c;
        if(!l[c-‘@‘] || j<l[c-‘@‘]) l[c-‘@‘]=j;
        if(!r[c-‘@‘] || j>r[c-‘@‘]) r[c-‘@‘]=j;
        if(!u[c-‘@‘] || i<u[c-‘@‘]) u[c-‘@‘]=i;
        if(!d[c-‘@‘] || i>d[c-‘@‘]) d[c-‘@‘]=i;
        a[c-‘@‘]=1;
        //cout<<map[i][j];
        //if(j==7)cout<<endl;
      }      

    memset(g,0,sizeof(g));
    for(int i=1;i<=26;i++)
      if(a[i])
      {
        for(int j=l[i];j<=r[i];j++)
        {
          if(map[u[i]][j]!=‘.‘) g[i][map[u[i]][j]-‘@‘]=1;
          if(map[d[i]][j]!=‘.‘) g[i][map[d[i]][j]-‘@‘]=1;
        }
        for(int j=u[i];j<=d[i];j++)
        {
          if(map[j][l[i]]!=‘.‘) g[i][map[j][l[i]]-‘@‘]=1;
          if(map[j][r[i]]!=‘.‘) g[i][map[j][r[i]]-‘@‘]=1;
        }
      }
    for(int i=1;i<=26;i++)
      for(int j=1;j<=26;j++)
        if(i!=j && g[i][j])
          D[j]++;
    p=0;
    dfs();
    return;
}

int main ()
{
    test();
    return 0;
}

test data:

USACO Training
Grader Results
14 users online
CHN/4 IND/4 KGZ/2 MKD/1 NED/1 USA/1 VNM/1

USER: cn tom [qq104801]
TASK: frameup
LANG: C++

Compiling...
Compile: OK

Executing...
   Test 1: TEST OK [0.003 secs, 3380 KB]
   Test 2: TEST OK [0.003 secs, 3380 KB]
   Test 3: TEST OK [0.003 secs, 3380 KB]
   Test 4: TEST OK [0.003 secs, 3380 KB]
   Test 5: TEST OK [0.003 secs, 3380 KB]
   Test 6: TEST OK [0.003 secs, 3380 KB]
   Test 7: TEST OK [0.005 secs, 3380 KB]
   Test 8: TEST OK [0.092 secs, 3380 KB]
   Test 9: TEST OK [0.292 secs, 3380 KB]

All tests OK.

YOUR PROGRAM (‘frameup‘) WORKED FIRST TIME! That‘s fantastic -- and a rare thing. Please accept these special automated congratulations.

Here are the test data inputs:

------- test 1 ----
9 8
.CCC....
ECBCBB..
DCBCDB..
DCCC.B..
D.B.ABAA
D.BBBB.A
DDDDAD.A
E...AAAA
EEEEEE..
------- test 2 ----
3 3
AAA
A.A
AAA
------- test 3 ----
5 7
AAA.CCC
A.A.C.C
AABBBCC
..B.B..
..BBB..
------- test 4 ----
11 8
UUUUU...
U...U...
U...EEEE
U...E..E
UMMMM..E
UMUUMEEE
.MJJJJJJ
.MJ.M..J
.MJ.M..J
.MJMM..J
..JJJJJJ
------- test 5 ----
6 9
AAABBBCCC
AQAQQQCQC
AAABBBCCC
XQXYYYZQZ
XQQYQYQQZ
XXXYYYZZZ
------- test 6 ----
20 20
AAABCDEFGHIJKLMNOPQR
A.ABCDEFGHIJKLMNOPQR
AAABCDEFGHIJKLMNOPQR
BBBBCDEFGHIJKLMNOPQR
CCCCCDEFGHIJKLMNOPQR
DDDDDDEFGHIJKLMNOPQR
EEEEEEEFGHIJKLMNOPQR
FFFFFFFFGHIJKLMNOPQR
GGGGGGGGGHIJKLMNOPQR
HHHHHHHHHHIJKLMNOPQR
IIIIIIIIIIIJKLMNOPQR
JJJJJJJJJJJJKLMNOPQR
KKKKKKKKKKKKKLMNOPQR
LLLLLLLLLLLLLLMNOPQR
MMMMMMMMMMMMMMMNOPQR
NNNNNNNNNNNNNNNNOPQR
OOOOOOOOOOOOOOOOOPQR
PPPPPPPPPPPPPPPPPPQR
QQQQQQQQQQQQQQQQQQQR
RRRRRRRRRRRRRRRRRRRR
------- test 7 ----
30 30
...............OOOOO..........
...............O...O..........
...............O...O..........
...............O...O..........
...............O...O..........
...............O...O..........
...............O...O..........
EEEEEEEEEEEEEEEOEEEOEEEEEEEEEE
E..............OOOOO.........E
E............................E
EEIIUUUUUUUUUUUUUUUUUUUUUUUUEE
..I.U...I..............AAAAUA.
..I.U...I..............A...UA.
..I.U...I..............A...UA.
..I.UUUUUUUUUUUUUUUUUUUUUUUUA.
..I.....I..............A....A.
..I.....I..............A....A.
..I.....I..............AAAAAA.
..I.....I.....................
..I.....I.....................
..I.....I.....................
..IIIIIII.....................
..............................
..............................
..............................
..............................
..............................
..............................
..............................
..............................
------- test 8 ----
30 30
..............................
.OOOOOOOOOYYYYYOO.............
.O....PPPPYPPPYPOPP...........
.O....P...Y...Y.O.P...........
.O....P...Y...Y.O.P...........
.O....P...Y...Y.O.P...........
.O....P...Y...Y.O.P...........
.O....P...Y...Y.O.P...........
.O....P...Y...Y.O.P...........
.O....P...Y...Y.O.P...........
.OOOOOOOOOYOOOYOEEEEEEEEE.....
......PPPPYPPPYPEPP.....E.....
..........Y...Y.E.......E.....
..WWWWWWWWWWWWWWWWWTT...E.....
..W...T...Y...Y.E.W.T...E.....
..W...T...Y...Y.E.W.T...E.....
..W...T...Y...Y.E.W.T...E.....
..W...T...YYYYY.EEWEEEEEE.....
UUWWWWWWWWWWWWWWWWW.T.........
U.....TTTTTTTTTTTTQQQQQQQQQQQ.
U....RRRRRRRRRRRRRQRRRRR....Q.
U....R............Q....R....Q.
UIIIIRRRRRRRRRRRRRQRRRRRIIIIQ.
UI................QQQQQQQQQQQ.
UUUUUUUUUUUUUUUUUUU........I..
.IIIIIIIIIIIIIIIIIIIIIIIIIII..
..............................
..............................
..............................
..............................
------- test 9 ----
30 30
.DDDDRRRRQGGGGGGGGGGGGGQQQQQQ.
.DSSDRSSSQGSRSSSSS....G.....Q.
.D..DR...QG.R....SEEEEEEEEE.Q.
.D..DRTTOOGOOOOOOOEOOOGOOOEOOO
.D..DRT.OQG.R....SE...G...ETQO
.D..DRT.OIGFFFFFFFEFFFGIIIEIQO
.D..DRT.CCCCCCCCCSE..FG...EIQO
.D..DRT.CIGFR...CSE..FG...EIQO
.D..DRT.CIGFR...CMEMMFGMMMEIMO
.DBBBBBBBBBBBBBBBBBBBBBBBBEIMO
.DB.DRT.CIGFR...CSE..FG..BEIMO
.DBLDLLHCHGFHHLLCLELLFGLOBEIMO
.DBLDRTHCIGAAAA.CSE..FGL.BEIM.
.DBDDRTHCIGARHA.CSE..FGL.BEIM.
.SBL.RTHCIGARHA.CSE..FGL.BEIM.
.SBLLLLHCIGALHALCLEKKFGKKBEIM.
.SB..RTHCIGARHANCNENNFG.KBEIM.
.SB..RTHCIGARHANCSE..FG.KBEIM.
.SBBBBBBBBBABBABBBBBBBBBBBEIM.
.S...RTHCIGAFFAFCFEFFFG.K.EIM.
.S...RTHCIGAGGAGCGEGGGG.K.EIM.
.S...RTHCIJAJHANCQEEEEEEEEEIM.
.S...RTHCI.AJHANCSK..N..K..IM.
.PPPPPPHCIIAIHAICIIIIIIIIIIIM.
.P...RTHCHHAHHANCSKKKKKKKTTTM.
.P...R.JCCCAAAACCS...N......M.
.P...R.JJJJJJ..NMS...N......M.
.PSSSRSSSSSSRSSNMMMMMMMMMMMMM.
.P...RRRRRRRR..N.....N......P.
.PPPPPPPPPPPPPPNNNNNNNPPPPPPP.

Keep up the good work!
Thanks for your submission!

时间: 2024-10-04 21:10:35

usaco-4.4-frameup-passed的相关文章

COGS 696. [IOI1996][USACO 2.3] 最长前缀

★   输入文件:prefix.in   输出文件:prefix.out   简单对比时间限制:1 s   内存限制:128 MB 描述 USACO 2.3.1 IOI96 在生物学中,一些生物的结构是用包含其要素的大写字母序列来表示的.生物学家对于把长的序列分解成较短的序列(即元素)很感兴趣. 如果一个集合 P 中的元素可以通过串联(元素可以重复使用,相当于 Pascal 中的 “+” 运算符)组成一个序列 S ,那么我们认为序列 S 可以分解为 P 中的元素.元素不一定要全部出现(如下例中B

USACO prefix TrieTree + DP

/* ID:kevin_s1 PROG:prefix LANG:C++ */ #include <iostream> #include <cstdio> #include <string> #include <cstring> #include <vector> #include <map> #include <set> #include <algorithm> #include <cstdlib>

【USACO 1.3.4】牛式

[題目描述 ] 下面是一个乘法竖式,如果用我们给定的那n个数字来取代*,可以使式子成立的话,我们就叫这个式子牛式. * * * x * * ---------- * * * * * * ---------- * * * * 数字只能取代*,当然第一位不能为0,况且给定的数字里不包括0. 注意一下在美国的学校中教的"部分乘积",第一部分乘积是第二个数的个位和第一个数的积,第二部分乘积是第二个数的十位和第一个数的乘积. 写一个程序找出所有的牛式. [格式] INPUT FORMAT: (f

USACO Chapter 1 Section 1.1

USACO的题解和翻译已经很多了... 我只是把自己刷的代码保存一下. 1.PROB Your Ride Is Here 1 /* 2 ID:xiekeyi1 3 PROG:ride 4 LANG:C++ 5 */ 6 7 #include<bits/stdc++.h> 8 using namespace std ; 9 10 int main() 11 { 12 freopen("ride.in","r",stdin); 13 freopen(&quo

USACO Your Ride Is Here

[USACO]Your Ride Is Here It is a well-known fact that behind every good comet is a UFO. These UFOs often come to collect loyal supporters from here on Earth. Unfortunately, they only have room to pick up one group of followers on each trip. They do,

usaco月赛,2017.1总结

T1:跳舞的奶牛 大致题意:一个体积为k的舞台能够同时容纳k只奶牛一起跳舞,他们每头奶牛的跳舞时间不同,如果有一只奶牛跳完了第k+1头奶牛就会立刻上场跳舞,当所有奶牛跳完舞以后我们认为这次表演结束.现在给出奶牛个数,最多用时,每头奶牛的跳舞时间.求舞台最小为多大. 思路:本来写了个程序以为这道题很简单,刚开始排一下序然后就行了,结果交了以后发现只过了五组,然后才发现这道题不能改变顺序(所以说为什么我改变顺序了还是能过五组,usaco的数据也好水......),所以说我想到了堆,然后就用堆写了一下

插入排序的优化【不靠谱地讲可以优化到O(nlogn)】 USACO 丑数

首先我们先介绍一下普通的插排,就是我们现在一般写的那种,效率是O(n^2)的. 普通的插排基于的思想就是找位置,然后插入进去,其他在它后面的元素全部后移,下面是普通插排的代码: 1 #include<iostream> 2 #include<fstream> 3 #include<stdio.h> 4 using namespace std; 5 int a[200000]; 6 int p[200000]; 7 8 int main(){ 9 ios::sync_wi

JPA:detached entity passed to persist

Caused by: org.hibernate.PersistentObjectException: detached entity passed to persist: com.example.entity.UserInfo at org.hibernate.event.internal.DefaultPersistEventListener.onPersist(DefaultPersistEventListener.java:124) at org.hibernate.event.inte

【日常学习】【最短路Dijkstra】codevs1069 usaco回家 题解

来源 usaco codevs1069 题目描述 Description 现在是晚餐时间,而母牛们在外面分散的牧场中. 农民约翰按响了电铃,所以她们开始向谷仓走去. 你的工作是要指出哪只母牛会最先到达谷仓(在给出的测试数据中,总会有且只有一只最快的母牛). 在挤奶的时候(晚餐前),每只母牛都在她自己的牧场上,一些牧场上可能没有母牛. 每个牧场由一条条道路和一个或多个牧场连接(可能包括自己). 有时,两个牧场(可能是字母相同的)之间会有超过一条道路相连. 至少有一个牧场和谷仓之间有道路连接. 因此

断句:Store all parameters but the first passed to this function as an array

// Store all parameters but the first passed to this function as an array //除了第一个参数,把调用publish函数时的所有传入参数保存为一个数组. var data = Array.prototype.slice.call(arguments, 1),