1. 程式人生 > 其它 >Codeforces Round #133 (Div. 2), A.【據圖推公式】 B.【思維+簡單dfs】

Codeforces Round #133 (Div. 2), A.【據圖推公式】 B.【思維+簡單dfs】

Problem - 216A - Codeforces

Problem - B - Codeforces

ATiling with Hexagons

題意: 給出a b c ,求裡面有多少個六邊形

題解:將六邊形補全為平行四邊形,如圖b c延長,把a覆蓋,直接底*高 - 2* 補全的小三角形

#include <iostream>

using namespace std;

int main()
{
    int a, b, c;
    cin >> a >> b >> c;
    cout << (b+a-1)*(c+a-1
)-a*(a-1)<<endl; return 0; }

BForming Teams

題意:n個人,組成兩個隊,不能讓敵人在一起。共n個人,m對敵人,每個人最多兩個敵人。我們可以去一些人使兩隊人數相等且沒有敵人在一起,求最少去多少人。

題解:有三種情況1.單邊 2.雙數環 3.單數環 對於1和2是可以平均分到兩隊的,而3就需要去掉一個人,還有就是最後的人數要是雙數。

#include <iostream>

using namespace std;

int n, res = 0;
int a[110][110];
void dfs(int init, int
x, int num) { int flag = 0; for(int i = 1; i <= n; i ++) { if(a[x][i] == 1) { a[x][i] = 0; a[i][x] = 0; if(i == init) { flag = 2; num ++; break; } dfs(init, i, num
+1); } } if(flag==2 && num > 2 && num%2==1) res ++; } int main() { int m; cin >> n >> m; while(m --) { int x, y; cin >> x >> y; a[x][y] = 1; a[y][x] = 1; } for(int i = 1; i <= n; i ++) { dfs(i, i, 0); } if((n-res)%2)res++; cout << res <<endl; return 0; }