發表文章

目前顯示的是 3月, 2016的文章

[ZJc079][UVA10346] Peter's Smokes

題目: http://zerojudge.tw/ShowProblem?problemid=c079 ==================================================== #include<cstdio> int main() {     int a, b;     while (scanf("%d%d",&a,&b)!=EOF){           int sum = a;           while (a >= b){                 sum += a / b ;                 a = a / b + a % b;           }           printf("%d\n",sum);     }     return 0; }

[CF]A. Gabriel and Caterpillar

題目: http://codeforces.com/problemset/problem/652/A --------------------------------------------------------------------------------- #include <bits/stdc++.h> using namespace std; const int n = 4e5 + 5; int main() {   int h1, h2;   int a, b;   scanf("%d%d",&h1,&h2);   scanf("%d%d",&a,&b);   h1 += 8 * a;   if(h1 >= h2){     printf("0\n");     return 0;   }   h1 -= 12 * b;   if(a <= b){     printf("-1\n");     return 0;   }   int day = 1;   for(int i=0;i<n;i++){     h1 += 12 * a;     if(h1 >= h2){       printf("%d\n",day);       return 0;     }     h1 -= 12 * b;     day++;   }   printf("-1\n");   return 0; }

[TIOJ]1011 . Edit Distance In Numbers

題目: http://tioj.ck.tp.edu.tw/problems/1011 -------------------------------------------------------------------------------------------- #include<cstdio> int main() { unsigned int a,b; while(scanf("%u%u",&a,&b)!=EOF) { unsigned int ans = 0; while(a != b) { if(a < b) { unsigned int t = a; a = b; b = t; } a /= 2; ans++; } printf("%u\n",ans); } return 0; }

[ZJ]b759: 我明明就有說過= =

題目: http://zerojudge.tw/ShowProblem?problemid=b759 ---------------------------------------------------------------------------------------------- #include<cstdio> #include<cstring> #define maxn 1000+10 int main(void) { char s[maxn]; memset(s,' ',sizeof(s)); while(scanf("%s",&s)!=EOF) { int len = strlen(s), a = 0; printf("%s\n",s); for(int i=1;i<len;i++) { a = i; for(int j=i;j<len;j++) { printf("%c",s[j]); if(j == len - 1) { for(int z=0;z<a;z++) printf("%c",s[z]); } } printf("\n"); } } return 0; }

[ZJ]a417: 螺旋矩陣

題目: http://zerojudge.tw/ShowProblem?problemid=a417 ---------------------------------------------------------------------------------------------------- #include<bits/stdc++.h> #define maxn 105 using namespace std; int main(void) { int T,a[maxn][maxn]; scanf("%d",&T); while(T --> 0) { int n,m,x,y,tot = 0; scanf("%d%d",&n,&m); memset(a,0,sizeof(a)); tot = a[x=0][y=0] = 1; if(m == 1) { while(tot < n*n) { while(y+1<n && !a[x][y+1]) a[x][++y] = ++tot; while(x+1<n && !a[x+1][y]) a[++x][y] = ++tot; while(y-1>=0 && !a[x][y-1]) a[x][--y] = ++tot; while(x-1>=0 && !a[x-1][y]) a[--x][y] = ++tot; } } else { while(tot < n*n) { while(x+1<n && !a[x+1][y]) a[++x][y] = ++tot; while(y+1<n && !a[x][y+1]) a[x][++y] = ++tot; while(x-1>=0 && !a[x-1][y])

[ZJ]a248: 新手訓練 ~ 陣列應用

題目: http://zerojudge.tw/ShowProblem?problemid=a248 -------------------------------------------------------------------------------------------- #include<cstdio> int main() {     int a, b, N;     while(scanf("%d %d %d", &a, &b, &N) == 3) {         printf("%d.", a/b), a %= b;         while(N--)         {         a *= 10; printf("%c", a/b+'0'); a %= b; }         puts("");     }     return 0; }

[ZJ]a244: 新手訓練 ~ for + if

題目: http://zerojudge.tw/ShowProblem?problemid=a244 ------------------------------------------------------------------------------------- #include<cstdio> int main(void) { int n,i=0,a; long long int b,c; scanf("%d",&n); while(i<n) { scanf("%d%lld%lld",&a,&b,&c); if(a==1) printf("%lld",b+c); else if(a==2) printf("%lld",b-c); else if(a==3) printf("%lld",b*c); else printf("%lld",b/c); printf("\n"); i++; } return 0; }

[ZJ]a225: 明明愛排列

題目: http://zerojudge.tw/ShowProblem?problemid=a225 -------------------------------------------------------------------------------------------------------- #include<cstdio> #include<cstdlib> #define N 1000+50 int main(void) { int n; while(scanf("%d",&n)!=EOF) { int x[N]={0}; int i,j,z=0,z2=0; for(i=0;i<n;i++) scanf("%d",&x[i]); for(i=n-1;i>0;i--) { for(j=0;j<i;j++) { if(x[j]%10 > x[j+1]%10) { z=x[j]; x[j]=x[j+1]; x[j+1]=z; } else if(x[j]%10==x[j+1]%10 && x[j]<x[j+1]) { z2=x[j]; x[j]=x[j+1]; x[j+1]=z2; } } } for(int i=0;i<n;i++) printf("%d ",x[i]); printf("\n"); } return 0; }

[ZJ]a216: 數數愛明明

題目: http://zerojudge.tw/ShowProblem?problemid=a216 ----------------------------------------------------------------------------------------------- #include<cstdio> typedef long long int LL; LL f (int n ) {            return n + n*(n-1) /2 ; } LL g (int n ) {          if (n==1 ){         return 1;      }        return f(n) + g(n-1) ; } int main(void) {     LL n;     while(scanf("%d",&n)!=EOF) { printf("%lld %lld\n",f(n),g(n));     } return 0; }

[ZJ]a148. You Cannot Pass?!

題目: http://zerojudge.tw/ShowProblem?problemid=a148 ------------------------------------------------------------------------------ #include<cstdio> int main() {     int n;     while(scanf("%d",&n)!=EOF) {     long long int a,sum =0 ;         for (int i=0 ;i<n;i++) scanf("%d",&a),sum += a;         printf("%s\n",(sum <=n *59 ?"yes" :"no" ));     }     return 0; }

[ZJ]a215: 明明愛數數

題目: http://zerojudge.tw/ShowProblem?problemid=a215 ----------------------------------------------------------------------------------------------- #include<cstdio> int main() { int a, b; while(scanf("%d%d",&a,&b)!=EOF) { int ans = 1; for(int i=0;i+a<=b;i++) ans++,b -= (a + i); printf("%d\n",ans); } return 0; }

[ZJ]b515: 摩斯電碼-商競103

題目: http://zerojudge.tw/ShowProblem?problemid=b515 ----------------------------------------------------------------------------------------------------------------------- #include<bits/stdc++.h> using namespace std ; string s[]={".-","-...","-.-.","-..",".","..-.","--.","....","..",".---","-.-",".-..","--","-.","---",".--.","--.-",".-.","...","-","..-","...-",".--","-..-","-.--","--.."} ; map<string,char> a ; string str; int main(){     for (int i=0;i<26;i++)         a[s[i]] = 'A' + i ;     int T;     scanf("%d",&T);     getline(cin,str) ;     while (T-- && getline(cin,str) ){         stringstream ss;         ss <<str;         string cha;         while (ss>

[ZJ]b520: 樂透-商競103

題目: #include<bits/stdc++.h> using namespace std; int getin() { int re = 0; char c; while (!isdigit(c = getchar()));   do {         re=10*re+c-'0';     }while (isdigit(c = getchar())) ;         return re; } int main() { int T; scanf("%d",&T); while(T--) { int a[7] = {0}, b[7] = {0}; for(int i=0;i<5;i++) a[i] = getin(); for(int i=0;i<5;i++) b[i] = getin(); sort(a,a+5); sort(b,b+5); int sum = 0; for(int i=0;i<5;i++) { for(int j=0;j<5;j++) { if(a[i] == b[j]) sum++; } } printf("%d\n",sum); } return 0; }

[ZJ]a647: 投資專家

題目: http://zerojudge.tw/ShowProblem?problemid=a647 -------------------------------------------------------------------------------------------------------- #include<bits/stdc++.h> using namespace std; #define maxn 1e-9 int main() { int T;     scanf("%d",&T);     while(T--)     {         long double m, p;         scanf("%Lf %Lf", &m, &p);         long double ans = (p/m-1)*100;         if( ans > -maxn ) printf("%.2Lf%% ", ans+maxn);         else printf("%.2Lf%% ", ans-maxn);         if( p/m-1 > 0.1-maxn || p/m-1 < -0.07+maxn) puts("dispose");         else puts("keep");     } }

[ZJ]d732: 二分搜尋法

題目: http://zerojudge.tw/ShowProblem?problemid=d732 --------------------------------------------------------------------------------------------------- #include<bits/stdc++.h> using namespace std; int binsrch(int num[], int len, int target){ int lower = 0; int upper = len-1; int mid=0; while(lower <= upper){ mid = (lower + upper) / 2; if(target > num[mid]) lower = mid + 1; else if(target < num[mid]) upper = mid - 1; else return mid + 1; } return 0; } int main(){ int len,query,i; cin>>len>>query; int num[len]; int target[query]; int ans[query]; for(i=0;i<len;i++) cin>>num[i]; for(i=0;i<query;i++){ cin>>target[i]; ans[i] = binsrch(num,len,target[i]); } for(i=0;i<query;i++) cout<<ans[i]<<"\n"; return 0; }

[ZJ]a149: 乘乘樂

題目: http://zerojudge.tw/ShowProblem?problemid=a149 ---------------------------------------------------------------------------------------------------------- #include<stdio.h> #include<stdlib.h> #include<string.h> #define N 100 int main() { int n,T; char x2[N]={' '}; int x[N]={0}; scanf("%d",&T); while(scanf("%s",&x2)!=EOF) { n=strlen(x2); for(int i=0;i<n;i++) x[i]=x2[i]-48; long long int ans=1; for(int i=0;i<n;i++) { ans*=x[i]; } printf("%lld\n",ans); } return 0; }

[ZJ]a147: Print it all

題目: http://zerojudge.tw/ShowProblem?problemid=a147 -------------------------------------------------------------------------------------------------------- #include<stdio.h> #include<stdlib.h> int main(void) {     int n,i;         while(scanf("%d",&n)!=EOF)     {     for(i=1;i<n;i++)     {                      if(i>0 && i%7!=0)                      {                             printf("%d ",i);                      }     }     printf("\n"); } }

[ZJ]a104: 排序

題目: http://zerojudge.tw/ShowProblem?problemid=a104 ------------------------------------------------------------------------------------------ #include<stdio.h> #include<stdlib.h> int main() {     int in0;     while (scanf("%d",&in0)!=EOF){           int in[in0];           for (int i=0;i<in0;i++)               scanf("%d",&in[i]);           for (int i=0;i<in0;i++)               for (int i1=0;i1<in0;i1++)                   if (in[i]<in[i1]){                      int a;                      a=in[i];                      in[i]=in[i1];                      in[i1]=a;                   }           for (int i=0;i<in0;i++)               printf("%d ",in[i]);           printf("\n");     }     return 0; }

[ZJ]a065: 提款卡密碼

題目: http://zerojudge.tw/ShowProblem?problemid=a065 --------------------------------------------------------------------------------------------------------- #include<stdio.h> #include<stdlib.h> int main() { char x[7]={' '}; while(scanf("%s",&x)!=EOF) { for(int i=0;i<7-1;i++) { printf("%d",abs(x[i+1]-x[i])); } printf("\n"); } return 0;  }

[ZJ]a095: 麥哲倫的陰謀

題目: http://zerojudge.tw/ShowProblem?problemid=a095 ------------------------------------------------------------------------------------------------------- #include<cstdio> int main() { int n,m; while(scanf("%d%d",&n,&m)!=EOF) { if(n == m) printf("%d\n",m); else printf("%d\n",m+1); } return 0; }

[ZJ]a053: Sagit's 計分程式

題目: http://zerojudge.tw/ShowProblem?problemid=a053 ------------------------------------------------------------------------------------------------- #include<stdio.h> #include<stdlib.h> int main() {     int in0 ,out ;     while (scanf("%d",&in0)!=EOF){           if (in0 >=40)              out=100 ;           else if (in0 >20)                out =80 +(in0 -20) *1 ;           else if (in0 >10)                out =60 +(in0 -10) *2 ;           else                out =in0 *6 ;           printf("%d \n",out);     }     return 0; }

[ZJ]a044: 空間切割

題目: http://zerojudge.tw/ShowProblem?problemid=a044 ---------------------------------------------------------------------------------------------------- #include<cstdio> int main(void) { int n; while(scanf("%d",&n)!=EOF) { printf("%d\n",(n*(n*n+5))/6+1); } return 0; }

[ZJ]a042: 平面圓形切割

題目: http://zerojudge.tw/ShowProblem?problemid=a042 --------------------------------------------------------------------------------------------------------- #include<stdio.h> int main(void) { int n; while(scanf("%d",&n)!=EOF) { n=n*(n-1)+2; printf("%d\n",n); } return 0; }

[ZJ]b761: 搶30

題目: http://zerojudge.tw/ShowProblem?problemid=b761 ----------------------------------------------------------------------------------------------------------------- #include<cstdio> int main() { int n; while(scanf("%d",&n)!=EOF) printf("%s\n",(n%4!=0)?"fat":"egg"); return 0; }