Volume 1. Elementary Problem Solving :: Maths - Misc Uva 113,10161,253,621,10025,591,107
2014-08-17 12:13
477 查看
刘汝佳 算法入门 第一版 Uva题目集合(五)
注:题目完成截止至107
注:题目完成截止至107
Uva 113
#include <stdio.h> #include <math.h> int main(){ int a; double b; while(scanf("%d %lf",&a,&b)!=EOF){ printf("%.0f\n",pow(b,1.0/a)); } return 0; }
Uva 10161
#include<stdio.h> #include<math.h> int main() { int n,m,i,x,y; while (scanf("%d",&n)==1) { if (n==0) break; m=(int)floor(sqrt((double)n-0.1)); x=m+1; if (n-m*m<=m+1) y=n-m*m; else {y=m+1;x-=n-m*m-m-1;} if (m%2==0) printf("%d %d\n",x,y); else printf("%d %d\n",y,x); } return 0; }
Uva 253
#include<stdio.h> char x[7],y[7],s[100]; bool z; bool pd(int a,int b,int c,int d,int e,int f) { if(x[a]!=y[1])return 0; if(x[b]!=y[2])return 0; if(x[c]!=y[3])return 0; if(x[d]!=y[4])return 0; if(x[e]!=y[5])return 0; if(x[f]!=y[6])return 0; return 1; } int main() { while(fgets(s,sizeof(s),stdin)) { int i;z=1; for(i=1;i<=6;i++)x[i]=s[i-1]; for(i=1;i<=6;i++)y[i]=s[i+5]; //上前左右后下!! if(z && pd(1,2,3,4,5,6) || z && pd(1,3,5,2,4,6))z=0;else if(z && pd(1,5,4,3,2,6) || z && pd(1,4,2,5,3,6))z=0;else if(z && pd(2,6,3,4,1,5) || z && pd(2,3,1,6,4,5))z=0;else if(z && pd(2,1,4,3,6,5) || z && pd(2,4,6,1,3,5))z=0;else if(z && pd(3,6,5,2,1,4) || z && pd(3,5,1,6,2,4))z=0;else if(z && pd(3,1,2,5,6,4) || z && pd(3,2,6,1,5,4))z=0;else if(z && pd(4,6,2,5,1,3) || z && pd(4,2,1,6,5,3))z=0;else if(z && pd(4,1,5,2,6,3) || z && pd(4,5,6,1,2,3))z=0;else if(z && pd(5,6,4,3,1,2) || z && pd(5,4,1,6,3,2))z=0;else if(z && pd(5,1,3,4,6,2) || z && pd(5,3,6,1,4,2))z=0;else if(z && pd(6,5,3,4,2,1) || z && pd(6,3,2,5,4,1))z=0;else if(z && pd(6,2,4,3,5,1) || z && pd(6,4,5,2,3,1))z=0; if(!z)printf("TRUE\n");else printf("FALSE\n"); } return 0; }
Uva 621
#include <stdio.h> #include <string.h> int main( ) { int t; int len; char s[ 1000 ]; scanf("%d",&t); while( t-- ) { scanf("%s",s); len = strlen( s ); if( (s[ 0 ] == '1' && len == 1) || (s[ 0 ] == '4' && len == 1 ) || ( s[ 0 ] == '7' && s[ 1 ] == '8' && len == 2 ) ) printf("+\n"); else if( s[ len-1 ] == '5' && s[ len-2 ] == '3' ) printf("-\n"); else if( s[ 0 ] == '9' && s[ len-1 ] == '4' ) printf("*\n"); else if( s[ 0 ] == '1' && s[ 1 ] == '9' && s[ 2 ] == '0' ) printf("?\n"); } return 0; }
Uva 10025
#include <iostream> #include <cstdio> #include <cstring> using namespace std; const int N=70000; int a ; int main() { int cnt=2; a[1]=1; while(1) { a[cnt]=a[cnt-1]+cnt; if(a[cnt]>1000000000) break; cnt++; } int t,t_cnt=0; scanf("%d",&t); while(t--) { int n,ans=1; scanf("%d",&n); if(n<0) n=-n; while(ans<cnt) { if(a[ans]>=n&&(a[ans]-n)%2==0) break; ans++; } if(t_cnt++!=0) puts(""); printf("%d\n",ans); } return 0; }
Uva 591
#include<stdio.h> int h[10001]; int n,i,a,b,ans; int main() { int j=0; while (scanf("%d",&n)==1) { b=0; if (n==0) return 0; for (i=1;i<=n;i++) { scanf("%d",&h[i]); b+=h[i]; } a=b/n; ans=0; for (i=1;i<=n;i++) { if ((h[i]-a)>=0) ans+=h[i]-a; else ans+=a-h[i]; } ans=ans/2; printf("Set #%d\n",++j); printf("The minimum number of moves is %d.\n\n",ans); } return 0; }
Uva 107
#include<stdio.h> #include<math.h> #include<string.h> //typedef unsigned __int64 UINT64; #define eps 1e-9 int main() { int n,h; while (scanf("%d%d",&h,&n)==2) { if(!n && !h) return 0; if(n==1 && h&1) {printf("0 %d\n",h);continue;} int i=0,j=0; double a,b; for(i=1;;i++) { a=pow(n,1.0/i); b=pow(h,1.0/i); //printf("####%.2lf %.2lf %d/n",a,b,i); if(fabs(b-a-1)<eps)break; } int ans1,ans2; ans1=(int)(a+eps); ans2=(int)(b+eps); int height_sum =ans2*h-n*ans1; // printf("%d %d/n",a,b); if(fabs(a-1)<eps) {printf("%d %d\n",i,height_sum);continue;} int num_sum=(n-1)/(ans1-1); printf("%d %d\n",num_sum,height_sum); } return 0; } /* 等比数列 N^i=num,(N+1)^i=H a^n=num,b^n=h; 循环得到n; 之后求解: num_sum=a^0+a^1+..a^(n-1); height_sum=a^0*b^n+..a^n*b^0=((b^n+1)-(a^n+1))/(b-a) */
相关文章推荐
- Volume 1. Elementary Problem Solving :: Maths - Number Theory Uva 575,10110,550,568,408,10061,10392
- Volume 1. Elementary Problem Solving :: Maths - Simple Geometry Uva 10250,579,375,10387,10112
- uva算法入门经典题解导航 - Volume 1. Elementary Problem Solving - Maths - Misc
- UVa Volume 1. Elementary Problem Solving :: String
- Volume 1. Elementary Problem Solving :: Big Number Uva 424,10106,465,748,10494
- Volume 1. Elementary Problem Solving :: String Uva 401,10010,10361,537,409
- uva算法入门经典题解导航 - Volume 1. Elementary Problem Solving - Maths - Simple Geometry
- OVa Online Judge 学习笔记- AOAPC I Volume 1. Elementary Problem Solving Big Number
- 【索引】Volume 1. Elementary Problem Solving
- 【索引】Volume 1. Elementary Problem Solving
- 【索引】Volume 1. Elementary Problem Solving
- Vomume 1.Elementary Problem Solving->volume 1 string 401-Palindromes
- [索引] Volume 1. Elementary Problem Solving
- Volume 1. Elementary Problem Solving->Volume 1 String 409 - Excuses, Excuses!
- Volume 1. Elementary Problem Solving->Volume 1 String 10115 - Automatic Editing
- uva算法入门经典题解导航 - Volume 1. Elementary Problem Solving
- Volume 1. Elementary Problem Solving->Volume 2 Big Number 10106 - Product
- [索引] Volume 1. Elementary Problem Solving
- uva算法入门经典题解导航 - Volume 1. Elementary Problem Solving - String
- uva算法入门经典题解导航 - Volume 1. Elementary Problem Solving - Sorting/Searching