标签:des c style class blog code
先上题目:
Time Limit: 10000/5000 MS
(Java/Others) Memory Limit: 32768/32768 K
(Java/Others)
Total Submission(s): 26 Accepted
Submission(s): 20
Special
Judge
1 #include <cstdio> 2 #include <cstring> 3 #include <algorithm> 4 #include <stack> 5 #include <utility> 6 #define MAX 32770 7 #define LL long long 8 using namespace std; 9 10 typedef pair<int,LL> pii; 11 12 pii s[MAX]; 13 int n,e; 14 LL f; 15 stack<int> st; 16 17 bool dfs(int c){ 18 if(!e){ 19 if(f%((n+1)/2)==0) return 1; 20 return 0; 21 } 22 for(int i=c;i<n;i++){ 23 st.push(s[i].first); 24 f+=s[i].second; 25 e--; 26 if(dfs(i+1)) return 1; 27 st.pop(); 28 f-=s[i].second; 29 e++; 30 } 31 return 0; 32 } 33 34 35 36 int main() 37 { 38 int t; 39 //freopen("data.txt","r",stdin); 40 scanf("%d",&t); 41 for(int z=1;z<=t;z++){ 42 scanf("%d",&n); 43 e = (n+1)>>1; 44 for(int i=0;i<n;i++){ 45 scanf("%I64d",&s[i].second); 46 s[i].first=i; 47 } 48 sort(s,s+n); 49 while(!st.empty()) st.pop(); 50 f=0; 51 printf("Case #%d:\n",z); 52 if(!dfs(0)) printf("-1"); 53 else for(int i=0;!st.empty();i++){ 54 if(i) putchar(‘ ‘); 55 printf("%d",st.top()); 56 st.pop(); 57 } 58 putchar(‘\n‘); 59 } 60 return 0; 61 }
百度之星2014复赛 - 1001 - Find Numbers,布布扣,bubuko.com
百度之星2014复赛 - 1001 - Find Numbers
标签:des c style class blog code
原文地址:http://www.cnblogs.com/sineatos/p/3762783.html