日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當(dāng)前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

Codeforces Gym 100342J Problem J. Triatrip 求三元环的数量 bitset

發(fā)布時間:2025/5/22 编程问答 26 豆豆
生活随笔 收集整理的這篇文章主要介紹了 Codeforces Gym 100342J Problem J. Triatrip 求三元环的数量 bitset 小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個參考.

?Problem J. Triatrip

Time Limit: 20 Sec

Memory Limit: 256 MB

題目連接

http://codeforces.com/gym/100342/attachments

Description

The travel agency “Four Russians” is offering the new service for their clients. Unlike other agencies that only suggest one-way or roundtrip for airline tickets to their customers, “Four Russians” offers the brand new idea — triatrip. Triatrip traveler starts in some city A, flies to some city B, then flies to some city C, and returns to the city A.
Now the managers of the agency started to wonder, how many different triatrips they can offer to their customers. Given a map of all possible flights, help them to find that out.

Input

The first line of the input file contains two integer numbers n — the number of cities that are served by airlines that agree to sell their tickets via the agency (3 ≤ n ≤ 1500). The following n lines contain a sequence of n characters each — the j-th character of the i-th line is ‘+’ if it is possible to fly from the i-th city to the j-th one, and ‘-’ if it is not. The i-th character of the i-th line is ‘-’.

Output

Output one integer number — the number of triatrips that the agency can offer to its customers.

Sample Input

4
--+-
+--+
-+--
--+-

Sample Output

2

HINT

?

題意

? ? ? 給出鄰接矩陣,有向圖,找出三元環(huán)的個數(shù)

題解

? ? bitset 暴力枚舉一條邊,出度入度的集合用到bitset

代碼:

1 //作者:1085422276 2 #include <cstdio> 3 #include <cmath> 4 #include <cstring> 5 #include <ctime> 6 #include <iostream> 7 #include <algorithm> 8 #include <set> 9 #include <vector> 10 #include <sstream> 11 #include <queue> 12 #include <typeinfo> 13 #include <fstream> 14 #include<bits/stdc++.h> 15 #include <map> 16 #include <stack> 17 typedef long long ll; 18 using namespace std; 19 const int inf = 10000000; 20 inline ll read() 21 { 22 ll x=0,f=1; 23 char ch=getchar(); 24 while(ch<'0'||ch>'9') 25 { 26 if(ch=='-')f=-1; 27 ch=getchar(); 28 } 29 while(ch>='0'&&ch<='9') 30 { 31 x=x*10+ch-'0'; 32 ch=getchar(); 33 } 34 return x*f; 35 } 36 ll exgcd(ll a,ll b,ll &x,ll &y) 37 { 38 ll temp,p; 39 if(b==0){ 40 x=1;y=0; 41 return a; 42 } 43 p=exgcd(b,a%b,x,y); 44 temp=x;x=y;y=temp-(a/b)*y; 45 return p; 46 } 47 //******************************* 48 #define N 1510 49 bitset<N> in[N],out[N],he; 50 char mp[1501][1501]; 51 int main() 52 { 53 54 freopen("triatrip.in","r",stdin); 55 freopen("triatrip.out","w",stdout); 56 int n; 57 n=read(); 58 for(int i=1;i<=n;i++) 59 scanf("%s",mp[i]); 60 for(int i=1;i<=n;i++) 61 { 62 for(int j=1;j<=n;j++) 63 { 64 if(i==j)continue; 65 if(mp[i][j-1]=='+') 66 { 67 in[i][j]=true; 68 out[j][i]=true; 69 } 70 } 71 } 72 ll ans=0; 73 for(int i=1;i<=n;i++) 74 { 75 for(int j=1;j<=n;j++) 76 { 77 if(i==j)continue; 78 if(mp[i][j-1]=='+') 79 he=(in[j])&(out[i]),ans+=he.count(); 80 } 81 } 82 cout<<ans/3<<endl; 83 return 0; 84 }

?

轉(zhuǎn)載于:https://www.cnblogs.com/zxhl/p/4710171.html

總結(jié)

以上是生活随笔為你收集整理的Codeforces Gym 100342J Problem J. Triatrip 求三元环的数量 bitset的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網(wǎng)站內(nèi)容還不錯,歡迎將生活随笔推薦給好友。