1、西工大C语言POJ作业T091、Houseboat#include #define PI 3.1415926int main()int i,n;double year,x,y;scanf(%d,&n);for(i=0;in;i+)scanf(%lf%lf,&x,&y);year=PI*(x*x+y*y)/100;printf(%d %dn,i+1,(int)year+1);return 0;T092、Sticks#include #include #include int len64, n, minlen, get;bool b64;int cmp(const void *a, const v
2、oid *b) return *(int *)a = n) return false; if(get = nowget) return true; int i; bool f = false; if(nowlen = 0) f = true; for(i = cnt; i n; i+) if(!bi) if(leni + nowlen = minlen) bi = true; if(dfs(0, nowget+1, nowget) return true; bi = false; return false; else if(leni + nowlen minlen) bi = true; if
3、(dfs(nowlen+leni, nowget, i+1) return true; bi = false; if(f) return false; while(i + 1 n & leni = leni+1) i+; return false;int main() int i, tollen; while(scanf(%d, &n), n) tollen = 0; int j = 0, p; for(i = 0; i n; i+) scanf(%d, &p); if(p = 50) lenj = p; tollen += lenj; j+; n = j; if(n = 0) printf(
4、0n); continue; qsort(len, n, sizeof(int), cmp); for(minlen = len0; ; minlen+) if(tollen % minlen) continue; memset(b, 0, sizeof(b); get = tollen / minlen; if(dfs(0, 0, 0) printf(%dn, minlen); break; return 0;T093、Checksum algorithm:#include int main()char a256;int i,sum;while(gets(a)&a0!=#)sum=0;for
5、(i=0;ai!=0;i+)if(ai!= )sum+=(i+1)*(ai-64);printf(%dn,sum);return 0;T094、Bee:#include int main()int n,a,b,sum,i,t;while(scanf(%d,&n)!=EOF&n!=-1)a=1,b=0,sum=0;for(i=0;in;i+)t=a;a=b+1;b=t+b;sum=a+b;printf(%d %dn,b,sum);return 0;T095、Graveyard:#include #include int main()int n,m,i;double s,a;while(scanf
6、(%d%d,&n,&m)!=EOF)if(n=0&m=0) break;s=0;for(i=1;in;i+)a=i*1.0/n*(n+m);s+=fabs(a-floor(a+0.5)/(n+m);/*放缩坐标系 floor(a+0.5)/(n+m) 找到离这个对应坐标的最近一个点 取得距离 累加移动距离 */printf(%.4fn,s*10000);return 0;T096、Road trip#includeint main() int n,i,speed,hour,h,s;/s是路程,h是上次的时间 while(scanf(%d,&n) & n!=-1) s=0; h=0; for(i
7、=1;i=n;i+) scanf(%d %d,&speed,&hour); s+=speed*(hour-h); h=hour; printf(%d,s); return 0;T097、Hanoi II#include #define M 70int startM, targeM;long long f(int *p, int k, int fina)if(k=0) return 0;if(pk=fina) return f(p,k-1,fina);return f(p,k-1,6-fina-pk)+(1LL(k-1);int main ()long long ans;int n, cas =
8、 0;while(scanf(%d,&n), n)for(int i = 1; i = n; i+) scanf(%d,&starti);for(int i = 1; i =1&startc=targec;c-);if(c=0) printf(0n); continue;int other = 6 - startc - targec;ans = f(start,c-1,other)+f(targe,c-1,other)+1;printf(%lldn,ans);return 0;T098、Redistribute wealth#include #include #include #include
9、 long long money1000001;long long C1000001;int main()int n,t,i,j;while(scanf(%d,&n)=1)int i;long long sum=0;for(i = 1;i=n;+i)scanf(%lld,&moneyi);sum += moneyi;long long M = sum/n;C1 = money1 - M;C0 = 0;for(i = 2;i=n-1;+i) Ci = Ci-1 + moneyi - M;for(i=0;in-1;i+)for(j=0;jCj+1)t=Cj;Cj=Cj+1;Cj+1=t;long
10、long mid = Cn/2;long long sum1 = 0;for(i = 0;i=n-1;+i)sum1 += abs(mid-Ci);printf(%lldn,sum1);return 0;T099、Dexter need help:#include int fun(int a)if(a=1) return 1;elsereturn fun(a/2)+1;int main()int a,x;while(scanf(%d,&a)&a!=0)x=fun(a);printf(%dn,x);return 0;T100、Specialized Numbers#include int fun
11、(int i,int r)int s=0;while(i)s+=i%r;i/=r;return s;int main()int i;for(i=2992;i10000;i+)if(fun(i,10)=fun(i,12)&fun(i,12)=fun(i,16)printf(%dn,i);return 0;T100、Specialized Numbers#include int fun(int i,int r)int s=0;while(i)s+=i%r;i/=r;return s;int main()int i;for(i=2992;i10000;i+)if(fun(i,10)=fun(i,12
12、)&fun(i,12)=fun(i,16)printf(%dn,i);return 0;(3)#include int main() int i, n, sum10, sum12, sum16; for (i=2992; i10000; i+) n = i; sum10 = 0; while (n) sum10 += n%10; n /= 10; n = i; sum12 = 0; while (n) sum12 += n%12; n /= 12; n = i; sum16 = 0; while (n) sum16 += n%16; n /= 16; if (sum10=sum12 & sum12=sum16) printf(%dn, i); return 0;
copyright@ 2008-2022 冰豆网网站版权所有
经营许可证编号:鄂ICP备2022015515号-1