UVA11889

Posted towboa

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了UVA11889相关的知识,希望对你有一定的参考价值。

lcm(a,b)=c

给a,c ,求最小的b

 

#include <iostream>
#include <cstring>
#include <sstream>
using namespace std;

#define int long long
int a,b,c;
int cnt[100];
int fac[100],tot ;

 int ksm(int x,int y)
 	if(y==0) return 1; int t=ksm(x,y/2);
 	if(y%2==0) return (t*t);
 	return t*t*x;
 
 void sov()
    cin>>a>>c;
    if(c%a)
    	printf("NO SOLUTION\\n");return;
    
    int i;
    tot=0;
	for(i=2;i*i<=c;i++)
		if(c%i==0)
			fac[++tot]=i;
			cnt[tot]=0;
			while(c%i==0) cnt[tot]++,c/=i;
		
	
	if(c>1)
		fac[++tot]=c; cnt[tot]=1;
	
	int ans= 1;
	for(i=1;i<=tot;i++)
		int t= 0;
		while(a%fac[i]==0)
			a/=fac[i];
			t++;
		
		if(t<cnt[i]) ans*=ksm(fac[i],cnt[i]);
	
	cout<<ans<<endl;
 
 signed main()
 	int tes;
 	cin>>tes;
    while(tes--) sov();
 
 
 

 

UVa中国麻将(Chinese Mahjong,Uva 11210)

简单的回溯题

 1 #include<iostream>
 2 #include<cstdio>
 3 #include<cstring>
 4 #include<algorithm>
 5 using namespace std;
 6 
 7 char *mahjong[]={
 8                                 "1T","2T","3T","4T","5T","6T","7T","8T","9T",
 9                                 "1S","2S","3S","4S","5S","6S","7S","8S","9S",
10                                 "1W","2W","3W","4W","5W","6W","7W","8W","9W",
11                                 "DONG","NAN","XI","BEI",
12                                 "ZHONG","FA","BAI"
13                                 };
14 
15 int convert(char *s)//映射处理
16 {
17     for(int i=0;i<34;i++)
18         if(strcmp(mahjong[i],s)==0)
19             return i;
20     return -1;
21 }
22 
23 int c[34];
24 
25 bool search(int dep)
26 {
27     for(int i=0;i<34;i++)//枚举刻子
28         if(c[i]>=3)
29         {
30             if(dep==3) return true;
31             c[i]-=3;
32             if(search(dep+1)) return true;
33             c[i]+=3;
34         }
35     for(int i=0;i<34;i++)//枚举顺子
36         if(i%9<=6&&c[i]>=1&&c[i+1]>=1&&c[i+2]>=1)
37         {
38             if(dep==3) return true;
39             c[i]--;c[i+1]--;c[i+2]--;
40             if(search(dep+1)) return true;
41             c[i]++;c[i+1]++;c[i+2]++;
42         }
43     return false;
44 }
45 
46 bool check()
47 {
48     for(int i=0;i<34;i++)//枚举将牌
49         if(c[i]>=2)
50         {
51             c[i]-=2;
52             if(search(0)) return true;
53             c[i]+=2;
54         }
55     return false;
56 }
57 
58 int main()
59 {
60     int casen=0;
61     int mj[15];
62     char s[100];
63     bool ok;
64     while(cin>>s)
65     {
66         if(s[0]==0) break;
67         printf("Case %d:",++casen);
68         mj[0]=convert(s);
69         for(int i=1;i<13;i++)
70         {
71             cin>>s;
72             mj[i]=convert(s);
73         }
74         ok=false;
75         for(int i=0;i<34;i++)//枚举听牌
76         {
77             memset(c,0,sizeof(c));
78             for(int j=0;j<13;j++) c[mj[j]]++;
79             if(c[i]>=4) continue;
80             c[i]++;
81             if(check())
82             {
83                 ok=true;
84                 printf(" %s",mahjong[i]);
85             }
86             c[i]--;
87         }
88         if(!ok)
89             printf(" Not ready");
90         printf("\n");
91     }
92     return 0;
93 }

 

以上是关于UVA11889的主要内容,如果未能解决你的问题,请参考以下文章

UVa 11889 最小公倍数

题解 UVa11889

Uva 11889 Benefit (lcm与gcd)

jdbc 得到表结构主键

2019年2月做题记录

uva是啥意思