1. 程式人生 > >2016ACM/ICPC亞洲區瀋陽站 - A/B/C/E/G/H/I - (Undone)

2016ACM/ICPC亞洲區瀋陽站 - A/B/C/E/G/H/I - (Undone)

連結:傳送門


A - Thickest Burger - [簽到水題]

ACM ICPC is launching a thick burger. The thickness (or the height) of a piece of club steak is A (1 ≤ A ≤ 100). The thickness (or the height) of a piece of chicken steak is B (1 ≤ B ≤ 100).
The chef allows to add just three pieces of meat into the burger and he does not allow to add three pieces of same type of meat. As a customer and a foodie, you want to know the maximum total thickness of a burger which you can get from the chef. Here we ignore the thickness of breads, vegetables and other seasonings.

Input
The first line is the number of test cases. For each test case, a line contains two positive integers A and B.

Output
For each test case, output a line containing the maximum total thickness of a burger.

Sample Input
10
68 42
1 35
25 70
59 79
65 63
46 6
28 82
92 62
43 96
37 28

Sample Output
178
71
165
217
193
98
192
246
235
102

Hint
Consider the first test case, since 68+68+42 is bigger than 68+42+42 the answer should be 68+68+42 = 178.
Similarly since 1+35+35 is bigger than 1+1+35, the answer of the second test case should be 1+35+35 = 71.

題意:

給出 $a,b$,輸出 $\max(a+a+b,a+b+b)$。

AC程式碼:

#include<bits/stdc++.h>
using
namespace std; int a,b; int main() { int T; scanf("%d",&T); while(T--) { scanf("%d%d",&a,&b); printf("%d\n",max(a+a+b,a+b+b)); } }

 


B - Relative atomic mass - [簽到水題]

Relative atomic mass is a dimensionless physical quantity, the ratio of the average mass of atoms of an element (from a single given sample or source) to $\frac{1}{2}$ of the mass of an atom of carbon-12 (known as the unified atomic mass unit).
You need to calculate the relative atomic mass of a molecule, which consists of one or several atoms. In this problem, you only need to process molecules which contain hydrogen atoms, oxygen atoms, and carbon atoms. These three types of atom are written as ’H’,’O’ and ’C’ repectively. For your information, the relative atomic mass of one hydrogen atom is 1, and the relative atomic mass of one oxygen atom is 16 and the relative atomic mass of one carbon atom is 12. A molecule is demonstrated as a string, of which each letter is for an atom. For example, a molecule ’HOH’ contains two hydrogen atoms and one oxygen atom, therefore its relative atomic mass is $18 = 2 \times 1 + 16$.

Input
The first line of input contains one integer $N(N \le 10)$, the number of molecules. In the next $N$ lines, the i-th line contains a string, describing the i-th molecule. The length of each string would not exceed 10.

Output
For each molecule, output its relative atomic mass.

Sample Input
5
H
C
O
HOH
CHHHCHHOH

Sample Output
1
12
16
18
46

題意:

氫元素重為 $1$,碳元素重為 $12$,氧元素重為 $16$,對輸入的字串(只包含 $C,H,O$)求和。

AC程式碼:

#include<bits/stdc++.h>
using namespace std;
string s;
int w[200];
int main()
{
    ios::sync_with_stdio(0);
    cin.tie(0);

    memset(w,0,sizeof(w));
    w['H']=1;
    w['C']=12;
    w['O']=16;
    int T;
    cin>>T;
    while(T--)
    {
        cin>>s;
        int ans=0;
        for(int k=0;k<s.size();k++) ans+=w[s[k]];
        cout<<ans<<endl;
    }
}

 


C - Recursive sequence - [矩陣快速冪加速遞推]

 


E - Counting Cliques - [暴力搜尋]

A clique is a complete graph, in which there is an edge between every pair of the vertices. Given a graph with N vertices and M edges, your task is to count the number of cliques with a specific size S in the graph.

Input
The first line is the number of test cases. For each test case, the first line contains 3 integers N,M and S (N ≤ 100,M ≤ 1000,2 ≤ S ≤ 10), each of the following M lines contains 2 integers u and v (1 ≤ u < v ≤ N), which means there is an edge between vertices u and v. It is guaranteed that the maximum degree of the vertices is no larger than 20.

Output
For each test case, output the number of cliques with size S in the graph.

Sample Input
3
4 3 2
1 2
2 3
3 4
5 9 3
1 3
1 4
1 5
2 3
2 4
2 5
3 4
3 5
4 5
6 15 4
1 2
1 3
1 4
1 5
1 6
2 3
2 4
2 5
2 6
3 4
3 5
3 6
4 5
4 6
5 6

Sample Output
3
7
15

題意:

給出一個 $n$ 個頂點 $m$ 條無向邊的圖,讓你求圖中,節點數為 $S$ 的完全圖有多少個。

題解:

DFS地去找就可以了,為了保證找出來的子圖沒有重複,應當認為規定只能往比編號比當前節點大的節點走。

AC程式碼:

#include<bits/stdc++.h>
using namespace std;
const int maxn=105;

int n,m,s;
int mp[maxn][maxn];
vector<int> v;

vector<int> G[maxn];

int ans;
bool vis[maxn];
void dfs(int now,vector<int>& v)
{
    if(v.size()==s)
    {
        ans++;
        return;
    }

    for(int i=0;i<G[now].size();i++)
    {
        int nxt=G[now][i];
        if(vis[nxt]) continue;

        bool ok=1;
        for(int k=0;k<v.size();k++) {
            if(!mp[v[k]][nxt]) {
                ok=0;
                break;
            }
        }
        if(ok)
        {
            v.push_back(nxt), vis[nxt]=1;
            dfs(nxt,v);
            v.pop_back(), vis[nxt]=0;
        }
    }
}

int main()
{
    ios::sync_with_stdio(0);
    cin.tie(0);

    int T;
    cin>>T;
    while(T--)
    {
        cin>>n>>m>>s;

        memset(mp,0,sizeof(mp));
        for(int i=1;i<=n;i++) G[i].clear();
        for(int i=1,u,v;i<=m;i++)
        {
            cin>>u>>v;
            if(u>v) swap(u,v);
            if(!mp[u][v])
            {
                G[u].push_back(v);
                mp[u][v]=mp[v][u]=1;
            }
        }

        ans=0;
        v.clear();
        memset(vis,0,sizeof(vis));
        for(int i=1;i<=n;i++)
        {
            v.push_back(i), vis[i]=1;
            dfs(i,v);
            v.pop_back(), vis[i]=0;
        }
        cout<<ans<<'\n';
    }
}

 


G - Do not pour out - [積分+二分] - (Undone)

 


H - Guessing the Dice Roll - [AC自動機+高斯消元] - (Undone)

 


I - The Elder - [樹形DP+斜率優化] - (Undone)