HDU4519
一种比较挫的写法
1 /* 2 模拟 3 */ 4 #include<stdio.h> 5 #include<string.h> 6 #include<stdlib.h> 7 #include<algorithm> 8 #include<iostream> 9 #include<queue> 10 #include<stack> 11 #include<math.h> 12 #include<map> 13 using namespace std; 14 const int maxn = 105; 15 16 int cmp( int a,int b ){ 17 return a>b; 18 } 19 20 int main(){ 21 int ca; 22 scanf("%d",&ca); 23 while( ca-- ){ 24 int n,m,k; 25 scanf("%d%d%d",&n,&k,&m); 26 int a[ maxn ]; 27 for( int i=0;i<n;i++ ) 28 a[i] = k; 29 int ans = 0; 30 while( 1 ){ 31 sort( a,a+n,cmp ); 32 if( a[0]<=0 ) break; 33 for( int i=0;a[i]>0&&i<min(n,m);i++ ) 34 a[ i ]--; 35 ans++; 36 } 37 printf("%d\n",ans); 38 } 39 return 0; 40 }
另外一种方法
1 /* 2 模拟 3 */ 4 #include<stdio.h> 5 #include<string.h> 6 #include<stdlib.h> 7 #include<algorithm> 8 #include<iostream> 9 #include<queue> 10 #include<stack> 11 #include<math.h> 12 #include<map> 13 using namespace std; 14 const int maxn = 105; 15 const double eps = 0.99999999; 16 17 int main(){ 18 int ca; 19 scanf("%d",&ca); 20 while( ca-- ){ 21 int n,m,k; 22 scanf("%d%d%d",&n,&k,&m); 23 if( m>=n ){ 24 printf("%d\n",k); 25 continue; 26 } 27 if( (n*k)%m==0 ) printf("%d\n",n*k/m); 28 else printf("%d\n",n*k/m+1); 29 } 30 return 0; 31 }
keep moving...