“美登杯”上海市高校大学生程序设计赛B. 小花梨的三角形(模拟,实现)
題目鏈接:https://acm.ecnu.edu.cn/contest/173/problem/B/#report9
Problem B B 、 小 花梨 的 三角形
時間限制:1000ms 空間限制:512MB
Description
小花梨現在有一個?層三角形圖(參考下圖),第?層有2? ? 1個邊長為1的等邊三角形。
每個交點處存在一個字符,總共有? + 1層字符,第?層有?個字符。
小花梨用等邊三角形三個頂點上的字符來表示這個三角形,兩個等邊三角形如果它們的三個
頂點字符相同(不區分順序)則視為同一類等邊三角形。小花梨想知道總共存在多少種不同類
別的等邊三角形。
Input
第一行為正整數?,表示三角形層數(1 ≤ ? ≤ 100)。
接下來? + 1行,第?行輸入?個字符,表示第?層的字符。(字符只包含小寫字母"? ? ?")
Output
輸出一個整數表示存在多少種不同類別的三角形
Example
Sample Input Sample Output
1
a
bc
1
2
a
bb
cac
3
3
a
aa
aaa
aaaa
1
Note
一:只存在頂點為(?,?,?)的三角形
二:存在頂點為(?,?,?) 、 (?,?,?) 、 (?,?,?)的3類不同的三角形
樣例三:只存在頂點為(?,?,?)的三角形
思路:
枚舉行,枚舉列,枚舉邊長,統計三個節點的字母,
排序后插入set中即可。
存在正的三角形,還存在倒立的三角形
細節見代碼:
#include <iostream> #include <cstdio> #include <cstring> #include <algorithm> #include <cmath> #include <queue> #include <stack> #include <map> #include <set> #include <vector> #include <iomanip> #define ALL(x) (x).begin(), (x).end() #define sz(a) int(a.size()) #define all(a) a.begin(), a.end() #define rep(i,x,n) for(int i=x;i<n;i++) #define repd(i,x,n) for(int i=x;i<=n;i++) #define pii pair<int,int> #define pll pair<long long ,long long> #define gbtb ios::sync_with_stdio(false),cin.tie(0),cout.tie(0) #define MS0(X) memset((X), 0, sizeof((X))) #define MSC0(X) memset((X), '\0', sizeof((X))) #define pb push_back #define mp make_pair #define fi first #define se second #define eps 1e-6 #define gg(x) getInt(&x) #define chu(x) cout<<"["<<#x<<" "<<(x)<<"]"<<endl using namespace std; typedef long long ll; ll gcd(ll a, ll b) {return b ? gcd(b, a % b) : a;} ll lcm(ll a, ll b) {return a / gcd(a, b) * b;} ll powmod(ll a, ll b, ll MOD) {ll ans = 1; while (b) {if (b % 2) { ans = ans * a % MOD; } a = a * a % MOD; b /= 2;} return ans;} inline void getInt(int *p); const int maxn = 1000010; const int inf = 0x3f3f3f3f; /*** TEMPLATE CODE * * STARTS HERE ***/ string temp; set<string> st; int n; string a[maxn]; int main() {//freopen("D:\\code\\text\\input.txt","r",stdin);//freopen("D:\\code\\text\\output.txt","w",stdout);gbtb;cin >> n;n++;repd(i, 1, n) {cin >> a[i];}repd(i, 1, n) {repd(j, 0, i - 1) {int x = i;int y = j;for (int len = 1;; len++) {temp = "";if (x + len > n) {break;}temp.pb(a[x][y]);temp.pb(a[x + len][y]);temp.pb(a[x + len][y + len]);sort(ALL(temp));st.insert(temp);}}}for (int i = n; i >= 1; --i) {repd(j, 0, i - 1) {int x = i;int y = j;for (int len = 1;; len++) {temp = "";if (x - len < 0 || y - len < 0 || y >= x - len ) {break;}temp.pb(a[x][y]);temp.pb(a[x - len][y]);temp.pb(a[x - len][y - len]);sort(ALL(temp));st.insert(temp);}}}cout << sz(st) << endl;return 0; }inline void getInt(int *p) {char ch;do {ch = getchar();} while (ch == ' ' || ch == '\n');if (ch == '-') {*p = -(getchar() - '0');while ((ch = getchar()) >= '0' && ch <= '9') {*p = *p * 10 - ch + '0';}} else {*p = ch - '0';while ((ch = getchar()) >= '0' && ch <= '9') {*p = *p * 10 + ch - '0';}} }轉載于:https://www.cnblogs.com/qieqiemin/p/11455504.html
總結
以上是生活随笔為你收集整理的“美登杯”上海市高校大学生程序设计赛B. 小花梨的三角形(模拟,实现)的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 原博客文章(Apache初配2008/4
- 下一篇: 心情-天气