#include <stdio.h> #include <stdlib.h> #define SIZE 999 int answer=0; int test_main(int data[SIZE]); int test_main(int data[SIZE]) { int map[25]={0}; for(int i=0;i<SIZE;i++){ map[data[i]]++; } /* for(int i=24;i>0;i=1-2){ if(map[i]!=0&&map[i/2]>1){ map[i]--; map[i/2]-=2; } if(map[i]==0||map[i/2]<1)break; } *///少while循环 for(int i=24;i>=0;i-=2){ while(map[i]>0){ if(map[i/2]>1){ map[i]--; map[i/2]-=2; } else break; } } for(int i=0;i<25;i++){ answer+=map[i]*i; } printf("%d\n",answer); return answer; //the sum of numbers in remaining cards after removing 3 cards each } void build_data(int data[SIZE]) { for (int i = 0; i < SIZE; i ++) { data[i] = rand() % 24 + 1; } } void main(void) { int data[SIZE]; for (int l = 0; l < 10; l++) { build_data(data); //printf("%d\n", test_main(data)); test_main(data); answer=0; } } /* #include <stdio.h> #include <stdlib.h> #include <iostream> using namespace std; void build_data(int data[999]) { for(int i=0; i<999; i++) { data[i]=rand()%24+1; } } int main() { int repeat[24]={0}; int data[999]={0}; for(int i=0;i<10;i++){ int repeat[24]={0}; int data[999]={0}; int m=0; int n=0; build_data(data); //算重复率 for(int i=0; i<999; i++) { m=data[i]; repeat[m-1]++; } // for(int i=0; i<24; i++){cout<<repeat[i]<<" ";} // cout<<endl; //开始消卡 for(int i=23; i>0; i-=2) { while(repeat[i]!=0&&repeat[(i-1)/2]>=2) { if(repeat[(i-1)/2]>=2) {repeat[i]--; repeat[(i-1)/2]=repeat[(i-1)/2]-2; } } } // for(int i=0; i<24; i++){cout<<repeat[i]<<" "<<endl;} //根据权重计算 for(int i=0; i<24; i++) {n=n+repeat[i]*(i+1);} cout<<n<<endl; } return 0; } */ /* #include <stdio.h> #include <stdlib.h> int test_main(int data[999]); int sum=0; void build_data(int data[999]) { for (int i = 0; i < 999; i ++) { data[i] = rand() % 24 + 1; } } void main(void) { int data[999]; for (int l = 0; l < 10; l++) { build_data(data); test_main(data); sum=0; }while(1); } int test_main(int data[999]) { int freq[24]={0}; for(int i=0;i<999;i++) { freq[data[i]-1]++; } for(int card=23;card>=0;card=card-2) { while(freq[card]>0) { if(freq[card/2]>1) { freq[card]--; freq[card/2]=freq[card/2]-2; } //would not be able to solve if the frequancy of 8 or 9 is more than 0 else break; } } int map[10][10]={0}; for(int i=0;i<10;i++){ for(int j=0;j<10;j++) { map[i][j]=i*j; } } for(int i=0;i<24;i++) { sum+=freq[i]*(i+1); } printf("%d\n", sum); return sum; //the sum of numbers in remaining cards after removing 3 cards each } */