标签:AtCoder get int abc209 len tail ans Problem include
-
-
- 简单哈希 + 反向建图
-
-
-
- 前向星或者邻接都可
-
-
-
- 为什么反向? 由结论推原因,当确定一个状态就不可改了,以为这样才是最优
-
#include <iostream>
#include<algorithm>
#include<cstdio>
#include<vector>
#include<queue>
using namespace std;
#define ll long long
const int N = 2e5 + 100;
vector<int> ans(N,-1);
vector<int> in(N);
vector<int> head(N);
vector<int> tail(N);
vector<int> G[N];
int get(char c){
if (c >= 'A' && c <= 'Z')return (c - 'A' + 26);
else return (c - 'a');
}
int get_hash(char a, char b, char c){
a = get(a); b = get(b); c = get(c);
return a * 52 * 52 + b * 52 + c;
}
int main(){
int n; cin >> n;
string s;
for (int i = 1, len; i <= n; i++) {
cin >> s; len = s.length();
head[i] = get_hash(s[0], s[1], s[2]);
tail[i] = get_hash(s[len - 3], s[len - 2], s[len - 1]);
in[head[i]]++;
G[tail[i]].push_back(head[i]);
}
queue<int> q;
for (int i = 0; i <= 150000; i++) {
if (!in[i]){
ans[i] = 0;
q.push(i);
}
}
while (!q.empty()) {
int u = q.front(); q.pop();
for (int i = 0; i<G[u].size(); i++) {
int v = G[u][i];
if (ans[v] == -1) {
in[v]--;
if (ans[u] == 0) ans[v] = 1, q.push(v);
else if (in[v] == 0)ans[v] = 0, q.push(v);
}
}
}
for (int i = 1; i <= n; i++){
if (ans[tail[i]] == -1) printf("Draw\n");
if (ans[tail[i]] == 0) printf("Takahashi\n");
if (ans[tail[i]] == 1) printf("Aoki\n");
}
return 0;
}
/*
4
abcadc adcopq adcrst rstppp
*/
标签:AtCoder,get,int,abc209,len,tail,ans,Problem,include 来源: https://blog.csdn.net/weixin_52068490/article/details/118937447
本站声明: 1. iCode9 技术分享网(下文简称本站)提供的所有内容,仅供技术学习、探讨和分享; 2. 关于本站的所有留言、评论、转载及引用,纯属内容发起人的个人观点,与本站观点和立场无关; 3. 关于本站的所有言论和文字,纯属内容发起人的个人观点,与本站观点和立场无关; 4. 本站文章均是网友提供,不完全保证技术分享内容的完整性、准确性、时效性、风险性和版权归属;如您发现该文章侵犯了您的权益,可联系我们第一时间进行删除; 5. 本站为非盈利性的个人网站,所有内容不会用来进行牟利,也不会利用任何形式的广告来间接获益,纯粹是为了广大技术爱好者提供技术内容和技术思想的分享性交流网站。