Nyist 489 Weeping Angel

Source: Internet
Author: User

Weeping Angel
Time Limit: 1000 MS | memory limit: 65535 KB
Difficulty: 5


Description
Doctor Who took Amy to a planet in TARDIS and opened the door to tadis. He found that there was a spectacular group of stone images on the planet, all of which were Angel stone images, and some of them were crying, some stone images are smiling, with a total of m rows and n columns. The doctor scanned the entire stone image group with a "Starting Sound" and obtained the number of Weeping Angels in each row. After walking with Amy for a while, the doctor suddenly remembered something and wondered if these stone images were a dark creature in the legend-"Weeping Angel"-a seemingly stone image, but it will move when people don't look at it. It will force people to be sent back to a previous time point and take time energy. The doctor didn't want to lose herself and Amy in an unknown time point, so the doctor immediately scanned the whole stone image group with a "Starting sound, I want to see whether the number of Weeping Angels in each row matches the number of angels. However, the more anxious it is, the more prone it is to errors. He accidentally scanned the errors, the number of Weeping Angels in each column is scanned. Now, due to the lack of sound speed, he cannot scan again. He wants to determine whether an angel has changed his expression based on the existing data, from crying to not crying or never crying to crying.

Input
The first line is an integer T, indicating a total of T group test data (T <= 50)
The first row of each group of test data is two integers, m, n (0 <m, n <= 300), indicating the number of rows and columns respectively.
The next two rows have m numbers and N numbers respectively, indicating the number of Weeping Angel portraits in m rows and the number of Weeping Angel portraits in n columns.


Output
If a stone image changes the expression according to the existing information, output terrible
If the stone image cannot be determined to be changed based on the existing information, the output is not sure (sometimes, you are sure that the status is the same for the two scans, but since there is no change between the two scans, therefore, not sure is also output)


Sample Input
2
2 3
1 1
1 1 0
3 3
0 1 2
3 0 0


Sample output
Not sure
Terrible


Source
[Zhang yuncong] original


Uploaded
Zhang yuncong

 

Problem solving: the largest stream is actually a dinic. it reverses the sink point of the source point, establishes a reverse graph, and determines the AC.

 1 #include <iostream> 2 #include <cstdio> 3 #include <cstring> 4 #include <cmath> 5 #include <algorithm> 6 #include <climits> 7 #include <vector> 8 #include <queue> 9 #include <cstdlib>10 #include <string>11 #include <set>12 #include <stack>13 #define LL long long14 #define pii pair<int,int>15 #define INF 0x3f3f3f3f16 using namespace std;17 const int maxn = 810;18 struct arc {19     int to,flow,next;20     arc(int x = 0,int y = 0,int z = -1) {21         to = x;22         flow = y;23         next = z;24     }25 };26 arc e[maxn*maxn];27 int head[maxn],d[maxn],cur[maxn];28 int tot,n,m,S,T;29 void add(int u,int v,int flow) {30     e[tot] = arc(v,flow,head[u]);31     head[u] = tot++;32     e[tot] = arc(u,0,head[v]);33     head[v] = tot++;34 }35 bool bfs() {36     queue<int>q;37     memset(d,-1,sizeof(d));38     d[T] = 1;39     q.push(T);40     while(!q.empty()) {41         int u = q.front();42         q.pop();43         for(int i = head[u]; ~i; i = e[i].next) {44             if(e[i].flow && d[e[i].to] == -1) {45                 d[e[i].to] = d[u] + 1;46                 q.push(e[i].to);47             }48         }49     }50     return d[S] > -1;51 }52 int dfs(int u,int low) {53     if(u == S) return low;54     int tmp = 0,a;55     for(int &i = cur[u]; ~i; i = e[i].next) {56         if(e[i].flow > 0 && d[e[i].to] == d[u] + 1&&(a=dfs(e[i].to,min(low,e[i].flow)))) {57             e[i].flow -= a;58             e[i^1].flow += a;59             tmp += a;60             low -= a;61             if(!low) break;62         }63     }64     if(!tmp) d[u] = -1;65     return tmp;66 }67 int dinic(int sum) {68     int ans = 0;69     while(bfs()) {70         memcpy(cur,head,sizeof(head));71         ans += dfs(T,INF);72         if(ans > sum) break;73     }74     return ans;75 }76 int main() {77     int tmp,sum,t,sum2;78     scanf("%d",&t);79     while(t--) {80         scanf("%d %d",&n,&m);81         memset(head,-1,sizeof(head));82         sum2 = sum = S = tot = 0;83         T = n+m+1;84         for(int i = 1; i <= n; i++){85             scanf("%d",&tmp);86             add(i,S,tmp);87             sum += tmp;88             for(int j = n+1; j <= n+m; ++j) add(j,i,1);89         }90         for(int i = 1; i <= m; ++i){91             scanf("%d",&tmp);92             add(T,n+i,tmp);93             sum2 += tmp;94         }95         printf("%s\n",sum == sum2&&dinic(sum) == sum?"Not Sure":"Terrible");96     }97     return 0;98 }
View code

 

Nyist 489 Weeping Angel

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.