uva 1341,siro1341

來源:互聯網
上載者:User

uva 1341,siro1341

題目連結:uva 1341 - Different Digits

題目大意:給定一個數字n,要求求一個數字m,m可以整除n,並且盡量組成的數字種類(0~9)盡量少,在種類相同的情況下數值盡量小。

解題思路:可以證明兩種數字肯定可以組成m,假設有數字k,一種數字可以有k,kk,kkk,kkkk,…整除n剩的數一定在0~n-1之間,所以肯定存在兩個由k數字組成的數字同模,那麼這兩個數相減所得到的數即使kkk00000,兩種數字。於是肯定了範圍,枚舉數字,然後用bfs擷取答案,維護最小值即可。

#include <cstdio>#include <cstring>#include <queue>#include <vector>#include <algorithm>using namespace std;const int maxn = 65536;int n, vis[maxn+10];struct state {    int key, len, vec[maxn];    state () {        key = 0;    }    bool operator < (const state& a) {        if (a.key == 0)            return true;        if (key == 0)            return false;        if (key != a.key)            return key < a.key;        if (len != a.len)            return len < a.len;        int l = len;        for (int i = 0; i < l; i++)            if (vec[i] != a.vec[i])                return vec[i] < a.vec[i];        return false;    }};struct node {    int mod, len, num;    void set (int mod, int num, int len) {        this->mod = mod;        this->num = num;        this->len = len;    }}que[maxn*2];void put (int d, state& w, int x) {    if (d < 0 || x < 0)        return;    w.vec[d] = que[x].num;    put(d-1, w, vis[que[x].mod]);}state judge (int a, int b) {    int head = 1, rear = 1;    memset(vis, -1, sizeof(vis));    state w;    node u, v;    w.key = (a==b?1:2);    if (a) {        que[rear++].set(a%n, a, 1);        vis[a%n] = 0;    }    if (b) {        que[rear++].set(b%n, b, 1);        vis[b%n] = 0;    }    while (head < rear) {        u = que[head++];        if (u.mod == 0) {            w.len = u.len;            put(u.len-1, w, head-1);            return w;        }        for (int i = 0; i < w.key; i++) {            int t = (i?b:a);            v.set((u.mod*10+t)%n, t, u.len+1);            if (vis[v.mod] != -1)                continue;            vis[v.mod] = head-1;;            que[rear++] = v;        }    }    w.key = 0;    return w;}int main () {    while (scanf("%d", &n) == 1 && n) {        state ans;        for (int i = 1; i <= 9; i++) {            state c = judge(i, i);            if (c < ans)                ans = c;        }        if (ans.key == 0) {            for (int i = 0; i <= 9; i++) {                for (int j = i+1; j <= 9; j++) {                    state c = judge(i, j);                    if (c < ans)                        ans = c;                }            }        }        for (int i = 0; i < ans.len; i++)            printf("%d", ans.vec[i]);        printf("\n");    }        return 0;}

隔離霜裡的PA++與PA+++是什?

SPF是指防晒指數 越高效果越好 但也會越油膩 一般在15~50左右比較好
PA是指對UVA的防護時間 一個+ 代表4小時 PA+++意味著防護UVA12個小時

但實際和理論值有著相當大的差距
防晒霜需要不斷補擦才會充分發揮效果

用紫外線(UV)烘乾的油墨來印刷的叫UV印刷
用紫外線(UV)烘乾的光油來上到印刷好的紙張上的叫UV上光
紫外線(UV)有殺菌的作用.

不知道回答的你是否清楚,滿意~~~?
 

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.