A暴力枚举
#include <vector>
#include <list>
#include <map>
#include <set>
#include <queue>
#include <string>
#include <deque>
#include <stack>
#include <algorithm>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <limits.h>
#include <time.h>
#include <string.h>
using namespace std;
int lowbit(int t){return t&(-t);}
int countbit(int t){return (t==0)?0:(1+countbit(t&(t-1)));}
int gcd(int a,int b){return (b==0)?a:gcd(b,a%b);}
#define LL long long
#define PI acos(-1.0)
#define N 55
#define Max INT_MAX
#define Min INT_MIN
#define eps 1e-8
#define FRE freopen("a.txt","r",stdin)
bool chk(int a,int b){
if(a==0&&b==0)return true;
if(a%10==b/10 && a/10==b%10)return true;
return false;
}
int main(){
int a,b;
while(scanf("%d:%d",&a,&b)!=EOF){
int tag=0;
b++;
int i,j;
for(i=a;a<=24;a++)
{
if(a==24)a=0;
for(j=b;b<=60;b++)
{
if(b==60){b=0;break;}
if(chk(a,b)){tag=1;break;}
}
if(tag)break;
}
if(a==0)printf("00:");
else
printf("%02d:",a);
if(b==0)
printf("00\n");
else
printf("%02d\n",b);
}
return 0;
}
B当长度为k时,所对应的最大值为2^k-1,平方后长度为2k,不信可以打表试试,所以如果存在k和2k,就不符合,如果存在某数处于k<x<2k,就可以输出YES!
3
11 1001
7
111 110001
15
1111 11100001
31
11111 1111000001
63
111111 111110000001
127
1111111 11111100000001
#include <vector>
#include <list>
#include <map>
#include <set>
#include <queue>
#include <string>
#include <deque>
#include <stack>
#include <algorithm>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <limits.h>
#include <time.h>
#include <string.h>
using namespace std;
int lowbit(int t){return t&(-t);}
int countbit(int t){return (t==0)?0:(1+countbit(t&(t-1)));}
int gcd(int a,int b){return (b==0)?a:gcd(b,a%b);}
#define LL long long
#define PI acos(-1.0)
#define N 100001
#define Max INT_MAX
#define Min INT_MIN
#define eps 1e-8
#define FRE freopen("a.txt","r",stdin)
int a[N];
int main(){
int n;
while(scanf("%d",&n)!=EOF){
int i,j;
for(i=0;i<n;i++)
scanf("%d",&a[i]);
sort(a,a+n);
int tag=0;
for(i=0;i<n-1 && !tag;i++)
if(a[i]!=a[i+1] && 2*a[i]>a[i+1])
tag=1;
if(tag)puts("YES");
else
puts("NO");
}
return 0;
}
C寻找一条没有环的路径,输出起始点和终点,输出路径最小值。
#include <vector>
#include <list>
#include <map>
#include <set>
#include <queue>
#include <string>
#include <deque>
#include <stack>
#include <algorithm>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <limits.h>
#include <time.h>
#include <string.h>
using namespace std;
int lowbit(int t){return t&(-t);}
int countbit(int t){return (t==0)?0:(1+countbit(t&(t-1)));}
int gcd(int a,int b){return (b==0)?a:gcd(b,a%b);}
#define LL long long
#define PI acos(-1.0)
#define N 1001
#define Max INT_MAX
#define Min INT_MIN
#define eps 1e-8
#define FRE freopen("a.txt","r",stdin)
int index[N];
int w[N];
int in[N];
int out[N];
int n,m;
struct node{
int a,b,c;
};
queue<node> q;
void init(){
int i,j;
for(i=0;i<=n;i++){
in[i]=0;
out[i]=0;
w[i]=Max;
index[i]=0;
}
while(!q.empty())q.pop();
}
void dfs(int x){
int minm=w[x];
node tmp;
tmp.a=x;
//x=index[x];
while(index[x]){
int t=index[x];
minm=min(minm,w[t]);
x=index[x];
}
tmp.b=x,tmp.c=minm;
q.push(tmp);
}
int main(){//FRE;
while(scanf("%d%d",&n,&m)!=EOF){
int i,j;
init();
for(i=1;i<=m;i++){
int a,b,c;
scanf("%d%d%d",&a,&b,&c);
index[a]=b;
w[a]=c;
out[a]++;
in[b]++;
}
int cnt=0;
for(i=1;i<=n;i++){
if(!in[i] && out[i])
{dfs(i);cnt++;}
}
printf("%d\n",cnt);
while(!q.empty()){
node tmp=q.front();
q.pop();
printf("%d %d %d\n",tmp.a,tmp.b,tmp.c);
}
}
return 0;
}
D排列组合问题 这个公式
#include <vector>
#include <list>
#include <map>
#include <set>
#include <queue>
#include <string>
#include <deque>
#include <stack>
#include <algorithm>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <limits.h>
#include <time.h>
#include <string.h>
using namespace std;
int lowbit(int t){return t&(-t);}
int countbit(int t){return (t==0)?0:(1+countbit(t&(t-1)));}
int gcd(int a,int b){return (b==0)?a:gcd(b,a%b);}
#define LL long long
#define PI acos(-1.0)
#define N 1001
#define Max INT_MAX
#define Min INT_MIN
#define eps 1e-8
#define FRE freopen("a.txt","r",stdin)
double C(int n,int m){
int i,j;
double s=1.0;
for(i=m;i>=1;i--){
s=s*n/i;
n--;
}
return s;
}
int d[1001];
int main(){//FRE;
int n,m,k;
while(scanf("%d%d%d",&n,&m,&k)!=EOF){
int i,j;
int sum=0;
for(i=1;i<=m;i++){
scanf("%d",&d[i]);
sum+=d[i];
}
if(sum<n){printf("-1.0\n");continue;}
int a=sum-1;
int b=n-1;
int c=d[k]-1;
double ans=1.0 - C(a-c,b)/C(a,b);
printf("%.6f\n",ans);
}
return 0;
}