POJ openjudge 个人测试 #3
1338.Ugly Numbers
二分下答案爆搜。。。
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 |
#include<set> #include<map> #include<cmath> #include<ctime> #include<queue> #include<cstdio> #include<vector> #include<cstring> #include<cstdlib> #include<iostream> #include<algorithm> #define mod 1000000007 #define inf 1000000000 #define eps 1e-1 #define ll long long using namespace std; ll read() { ll x=0,f=1;char ch=getchar(); while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();} while(ch>='0'&&ch<='9'){x=x*10+ch-'0';ch=getchar();} return x*f; } ll mid; int n,tot; int p[3]={2,3,5}; void dfs(ll x,int last) { if(tot==n)return; if(x>mid)return; tot++; for(int i=0;i<=2;i++) if(p[i]>=last) dfs(x*p[i],p[i]); } int main() { while(1) { n=read(); if(n==0)return 0; ll l=1,r=10000000000LL; while(l<=r) { mid=(l+r)>>1; tot=0; dfs(1,2); if(tot==n)r=mid-1; else l=mid+1; } printf("%lld\n",l); } return 0; } |
1250.Tanning Salon
模拟
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 |
#include<set> #include<map> #include<cmath> #include<ctime> #include<queue> #include<cstdio> #include<vector> #include<cstring> #include<cstdlib> #include<iostream> #include<algorithm> #define mod 1000000007 #define inf 1000000000 #define eps 1e-1 #define ll long long using namespace std; ll read() { ll x=0,f=1;char ch=getchar(); while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();} while(ch>='0'&&ch<='9'){x=x*10+ch-'0';ch=getchar();} return x*f; } int n,now,num[105]; char a[100005]; int main() { while(1) { memset(num,0,sizeof(num));now=0; n=read(); if(n==0)return 0; scanf("%s",a+1); int l=strlen(a+1),ans=0; for(int i=1;i<=l;i++) if(num[a[i]-'A']) { num[a[i]-'A']--; if(!num[a[i]-'A'])now--; } else { if(now<n)now++; else ans++; num[a[i]-'A']++; } if(ans==0)puts("All customers tanned successfully."); else printf("%d customer(s) walked away.\n",ans); } return 0; } |
1270.Following Orders
又是尼玛爆搜。。。
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 |
#include<set> #include<map> #include<cmath> #include<ctime> #include<queue> #include<cstdio> #include<vector> #include<cstring> #include<cstdlib> #include<iostream> #include<algorithm> #define mod 1000000007 #define inf 1000000000 #define ll long long using namespace std; ll read() { ll x=0,f=1;char ch=getchar(); while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();} while(ch>='0'&&ch<='9'){x=x*10+ch-'0';ch=getchar();} return x*f; } int top,cnt; int b[105],last[105],ans[105],mark[105]; int d[105],tmp[105]; string a; struct edge{ int to,next; }e[5005]; void insert(int u,int v) { e[++cnt]=(edge){v,last[u]};last[u]=cnt; d[v]++; } bool check(int x,int id) { for(int i=1;i<=top;i++)tmp[b[i]]=d[b[i]]; for(int i=1;i<x;i++) { int t=ans[i]; for(int j=last[t];j;j=e[j].next) tmp[e[j].to]--; } return tmp[id]==0; } void dfs(int x) { if(x==top+1) { for(int i=1;i<=top;i++) printf("%c",ans[i]+'a'); puts(""); return; } for(int i=1;i<=top;i++) if(!mark[i]&&check(x,b[i])) { ans[x]=b[i]; mark[i]=1; dfs(x+1); mark[i]=0; } } int main() { while(getline(cin,a)) { cnt=top=0; memset(last,0,sizeof(last)); memset(d,0,sizeof(d)); for(int i=0;i<a.length();i+=2) b[++top]=a[i]-'a'; sort(b+1,b+top+1); getline(cin,a); for(int i=0;i<a.length();i+=4) insert(a[i]-'a',a[i+2]-'a'); dfs(1); puts(""); } return 0; } |
1978.Hanafuda Shuffle
傻逼模拟
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 |
#include<set> #include<map> #include<cmath> #include<ctime> #include<queue> #include<cstdio> #include<vector> #include<cstring> #include<cstdlib> #include<iostream> #include<algorithm> #define mod 1000000007 #define inf 1000000000 #define pi acos(-1) #define ll long long using namespace std; ll read() { ll x=0,f=1;char ch=getchar(); while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();} while(ch>='0'&&ch<='9'){x=x*10+ch-'0';ch=getchar();} return x*f; } int n,m,a[55],b[55]; bool mark[55]; void solve(int p,int c) { int now=0; memset(mark,0,sizeof(mark)); for(int i=1;i<=c;i++) b[++now]=a[p+i-1],mark[p+i-1]=1; for(int i=1;i<=n;i++) if(!mark[i])b[++now]=a[i]; for(int i=1;i<=n;i++)a[i]=b[i]; } int main() { while(1) { n=read();m=read(); if(!n)return 0; for(int i=1;i<=n;i++) a[i]=n-i+1; while(m--) { int p=read(),c=read(); solve(p,c); } printf("%d\n",a[1]); } return 0; } |
1799.Yeehaa!
二分解方程。。。
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 |
#include<set> #include<map> #include<cmath> #include<ctime> #include<queue> #include<cstdio> #include<vector> #include<cstring> #include<cstdlib> #include<iostream> #include<algorithm> #define mod 1000000007 #define inf 1000000000 #define pi acos(-1) #define ll long long using namespace std; ll read() { ll x=0,f=1;char ch=getchar(); while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();} while(ch>='0'&&ch<='9'){x=x*10+ch-'0';ch=getchar();} return x*f; } int T,n; double R; int main() { T=read(); for(int cas=1;cas<=T;cas++) { printf("Scenario #%d:\n",cas); scanf("%lf%d",&R,&n); double lm=0,rm=R,mid; for(int i=1;i<=50;i++) { mid=(lm+rm)/2; if(mid/(R-mid)<sin(pi/n))lm=mid; else rm=mid; } printf("%.3lf\n",lm); puts(""); } return 0; } |
Subscribe