锘??xml version="1.0" encoding="utf-8" standalone="yes"?>亚洲综合视频1区,亚洲欧美日韩另类,欧美丝袜一区二区http://www.shnenglu.com/goAheadtw/category/15891.htmlhahazh-cnWed, 02 Feb 2011 02:09:05 GMTWed, 02 Feb 2011 02:09:05 GMT60hdu3440(宸垎綰︽潫)http://www.shnenglu.com/goAheadtw/articles/139140.htmltwtwSat, 22 Jan 2011 17:13:00 GMThttp://www.shnenglu.com/goAheadtw/articles/139140.htmlhttp://www.shnenglu.com/goAheadtw/comments/139140.htmlhttp://www.shnenglu.com/goAheadtw/articles/139140.html#Feedback0http://www.shnenglu.com/goAheadtw/comments/commentRss/139140.htmlhttp://www.shnenglu.com/goAheadtw/services/trackbacks/139140.html棰樼洰緗戝潃錛?http://acm.hdu.edu.cn/showproblem.php?pid=3440 

House Man

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 446    Accepted Submission(s): 157


Problem Description
In Fuzhou, there is a crazy super man. He can’t fly, but he could jump from housetop to housetop. Today he plans to use N houses to hone his house hopping skills. He will start at the shortest house and make N-1 jumps, with each jump taking him to a taller house than the one he is jumping from. When finished, he will have been on every house exactly once, traversing them in increasing order of height, and ending up on the tallest house.
The man can travel for at most a certain horizontal distance D in a single jump. To make this as much fun as possible, the crazy man want to maximize the distance between the positions of the shortest house and the tallest house.
The crazy super man have an ability鈥攎ove houses. So he is going to move the houses subject to the following constraints:
1. All houses are to be moved along a one-dimensional path.
2. Houses must be moved at integer locations along the path, with no two houses at the same location.
3. Houses must be arranged so their moved ordering from left to right is the same as their ordering in the input. They must NOT be sorted by height, or reordered in any way. They must be kept in their stated order.
4. The super man can only jump so far, so every house must be moved close enough to the next taller house. Specifically, they must be no further than D apart on the ground (the difference in their heights doesn't matter).
Given N houses, in a specified order, each with a distinct integer height, help the super man figure out the maximum possible distance they can put between the shortest house and the tallest house, and be able to use the houses for training.
 

Input
In the first line there is an integer T, indicates the number of test cases.(T<=500)
Each test case begins with a line containing two integers N (1 ≤ N ≤ 1000) and D (1 ≤ D ≤1000000). The next line contains N integer, giving the heights of the N houses, in the order that they should be moved. Within a test case, all heights will be unique.
 

Output
For each test case , output “Case %d: “first where d is the case number counted from one, then output a single integer representing the maximum distance between the shortest and tallest house, subject to the constraints above, or -1 if it is impossible to lay out the houses. Do not print any blank lines between answers.
 

Sample Input
3 4 4 20 30 10 40 5 6 20 34 54 10 15 4 2 10 20 16 13
 

Sample Output
Case 1: 3 Case 2: 3 Case 3: -1

// Bellman_Ford 
#include <stdio.h>
#include 
<memory>
#include 
<iostream>
#include 
<algorithm>
#include 
<cstring>
#include 
<vector>
#include 
<map>
#include 
<cmath>
#include 
<set>
#include 
<queue>
#include 
<time.h> 
#include 
<limits>
using namespace std;
#define typev int
#define N 1005
#define inf 0x7fffffff 
#define E (N*5) 
const double pi = acos(-1.0); 
struct e{
    
int st, ed; 
    typev len;  
    
void set(int _st, int _ed, typev _len){
        st 
= _st; 
        ed 
= _ed; 
        len 
= _len; 
    }
}es[E];
struct node{
    
int h; 
    
int i; 
}nodes[N];
e
* fir[N]; 
int n, en, d;
int st, ed; 
int vis[N], t[N], que[N]; 
typev dist[N]; 
inline 
bool cmp(node n1, node n2){
    
return n1.h < n2.h; 
}
inline 
bool relax(int st, int ed, int len){
    
if(dist[st] < inf && dist[ed] > dist[st] + len){
        dist[ed] 
= dist[st] + len;
        
return true
    }
    
return false
}
bool Bellman_Ford(int n, int st){  //榪斿洖true琛ㄧず鏈夎礋鐜?/span>
    int i, j; 
    
bool flag; 
    
for(i = 0; i < n; i++) dist[i] = inf; 
    dist[st] 
= 0
    
for(i = 0; i < n; i++){
        flag 
= false
        
for(j = 0; j < en; j++){
            
if(relax(es[j].st, es[j].ed, es[j].len)) flag = true
        }
        
if(!flag) break
    }
    
return flag;  
}
int cnt = 0
int main(){
#ifndef ONLINE_JUDGE
    freopen(
"in.txt""r", stdin); 
    
//freopen("out.txt", "w", stdout); 
#endif 

    
int t, i, ans, u, v;
    scanf(
"%d"&t);
    
while(t--){
        scanf(
"%d%d"&n, &d);
        
for(i = 0; i < n; i++){
            scanf(
"%d"&nodes[i].h);
            nodes[i].i 
= i; 
        }
        en 
= st = ed = 0
        sort(nodes, nodes
+n, cmp); 
        st 
= nodes[0].i; 
        ed 
= nodes[n - 1].i; 
        
if(st > ed) swap(st, ed); 
        
for(i = 0; i < n; i++) fir[i] = NULL; 
        
for(i = 1; i < n; i++){
            es[en
++].set(i, i-1-1); 
            u 
= nodes[i].i; 
            v 
= nodes[i - 1].i; 
            
if(u < v){
                es[en
++].set(u, v, d); 
            }
else es[en++].set(v, u, d); 
        } 
        
if(!Bellman_Ford(n, st)) ans = dist[ed];
        
else ans = -1
        printf(
"Case %d: %d\n"++cnt, ans);

    }
    
return 0;
}





tw 2011-01-23 01:13 鍙戣〃璇勮
]]>
hdu3436(鏁版嵁緇撴瀯)http://www.shnenglu.com/goAheadtw/articles/139120.htmltwtwSat, 22 Jan 2011 08:58:00 GMThttp://www.shnenglu.com/goAheadtw/articles/139120.htmlhttp://www.shnenglu.com/goAheadtw/comments/139120.htmlhttp://www.shnenglu.com/goAheadtw/articles/139120.html#Feedback0http://www.shnenglu.com/goAheadtw/comments/commentRss/139120.htmlhttp://www.shnenglu.com/goAheadtw/services/trackbacks/139120.html
#include <stdio.h>
#include 
<memory>
#include 
<iostream>
#include 
<algorithm>
#include 
<cstring>
#include 
<vector>
#include 
<map>
#include 
<cmath>
#include 
<set>
#include 
<queue>
#include 
<time.h> 
#include 
<limits>
using namespace std;
#define N 100005
#define typev int 
typev ar[N
*2]; 
int ks[N], num[N], pos[N], id[N];
bool has[N]; 
int kn, n, qn, fr; 
char qs[N]; 
int vMax; 
int lowb(int t){ return t & (-t); }
void add(int i, typev v){
    
for(; i < vMax; ar[i] += v, i += lowb(i)) ; 
}
typev sum(
int i){
    typev s 
= 0;
    
for(; i > 0; s += ar[i], i -= lowb(i));
    
return s; 
}
int find_k(int k){ //find the kth number
    int pos = 0, cnt = 0, i; 
    
for(i = log((double)vMax) / log(2.0+ 1; i >= 0; i--){
        pos 
+= (1 << i); 
        
if(pos >= vMax || cnt + ar[pos] >= k) pos -= (1 << i); 
        
else cnt += ar[pos]; 
    }
    
return pos + 1
}
bool input(){
    scanf(
"%d%d"&n, &qn);
    
int i; 
    
char ops[10]; 
    
for(i = 0; i < qn; i++){
        scanf(
"%s%d", ops, num+i);
        ks[i] 
= num[i]; 
        qs[i] 
= ops[0]; 
    }
    
return true
}
void init(){
    kn 
= qn; 
    ks[kn
++= 1
    sort(ks, ks
+kn);  
    
int i, j; 
    j 
= 1;
    
for(i = 1; i < kn; i++){
        
if(ks[i] != ks[j-1]) ks[j++= ks[i]; 
    }
    kn 
= j; 
    vMax 
= qn + kn + 1
    fill(ar, ar
+vMax+10); 
    fr 
= qn; 
}
int cnt = 0
void solve(){
    
int i, pMax, val, p, s, ans; 
    init(); 
    ks[kn] 
= n+1
    
for(i = 0; i < kn; i++){
        has[i] 
= true
        val 
= ks[i+1]-ks[i]; 
        pos[i] 
= qn + i + 1
        add(pos[i], val); 
    }
    printf(
"Case %d:\n"++cnt);
    
for(i = 0; i < qn; i++){
        
if(qs[i] == 'T'){
            p 
= lower_bound(ks, ks+kn, num[i]) - ks; 
            has[p] 
= false
            val 
= -1
            add(pos[p], val); 
            val 
= 1
            id[fr] 
= num[i]; 
            pos[p] 
= fr--
            add(pos[p], val); 
        }
else if(qs[i] == 'R'){
            p 
= find_k(num[i]); 
            
if(p <= qn){
                ans 
= id[p]; 
            }
else{
                s 
= sum(p-1); 
                ans 
= num[i] - s + ks[p - qn - 1- 1
                
if(!has[p - qn - 1]) ans++
            }
            printf(
"%d\n", ans);
        }
else//'Q'
            p = lower_bound(ks, ks+kn, num[i]) - ks; 
            ans 
= sum(pos[p] - 1); 
            printf(
"%d\n", ans + 1);
        }
    }
}
int main(){
#ifndef ONLINE_JUDGE
    freopen(
"in.txt""r", stdin); 
    
//freopen("out.txt", "w", stdout); 
#endif 
    
int t; 
    scanf(
"%d"&t);
    
while(t--){
        input(); 
        solve(); 
    }
    
return 0;
}







tw 2011-01-22 16:58 鍙戣〃璇勮
]]>
hdu3433(dp)http://www.shnenglu.com/goAheadtw/articles/139038.htmltwtwFri, 21 Jan 2011 08:44:00 GMThttp://www.shnenglu.com/goAheadtw/articles/139038.htmlhttp://www.shnenglu.com/goAheadtw/comments/139038.htmlhttp://www.shnenglu.com/goAheadtw/articles/139038.html#Feedback0http://www.shnenglu.com/goAheadtw/comments/commentRss/139038.htmlhttp://www.shnenglu.com/goAheadtw/services/trackbacks/139038.htmlhttp://acm.hdu.edu.cn/showproblem.php?pid=3433 
/* 
棰樼洰鎻忚堪: N涓漢,絎琲涓漢瀹屾垚涓涓狝浠誨姟闇瑕佹椂闂碼i,瀹屾垚涓涓狟浠誨姟闇瑕佹椂闂碽i錛?br>鐜板湪鍙圶涓換鍔鍜孻涓換鍔錛屾眰瀹屾垚鎵鏈変換鍔℃墍闇瑕佺殑鏈鐭椂闂淬?br>瑙f硶錛氫簩鍒嗘椂闂磘錛宒p[i][j]琛ㄧず鍓峣涓漢瀹屾垚j涓狝浠誨姟鎵鑳藉瀹屾垚鐨凚浠誨姟鐨勬暟閲?br>
*/ 
#include 
<stdio.h>
#include 
<memory>
#include 
<iostream>
#include 
<algorithm>
#include 
<cstring>
#include 
<vector>
#include 
<map>
#include 
<cmath>
#include 
<set>
#include 
<queue>
#include 
<time.h> 
#include 
<limits>
using namespace std;
#define XY 205
#define N 55
#define inf 0x7fffffff
int a[N], b[N], dp[XY], n, X, Y; 
bool check(int t){  //鍒ゆ柇鍦ㄦ椂闂磘鍐呮槸鍚﹀彲浠ュ畬鎴愭墍鏈夌殑浠誨姟
    int i, j, k, kMax; 
    
for(i = 1; i <= X; i++) dp[i] = -1
    dp[
0= 0
    
for(i = 0; i < n; i++){
        kMax 
= min(X, t / a[i]); 
        
if(dp[X] >= Y) return true
        
for(j = X; j >= 0; j--){  
            
for(k = 0; k <= kMax && j - k>= 0; k++){  //絎琲涓漢瀹屾垚k浠?/span>
                if(dp[j-k] < 0continue
                dp[j] 
= max(dp[j], dp[j - k] + (t - k * a[i]) / b[i]); 
            }
        }
    }
    
return dp[X] >= Y; 
}
int main(){
#ifndef ONLINE_JUDGE
    freopen(
"in.txt""r", stdin); 
    
//freopen("out.txt", "w", stdout); 
#endif 
    
int t, i,ca, low, high, mid; 
    scanf(
"%d"&t);
    
for(ca = 1; ca <= t; ca++){
        scanf(
"%d%d%d"&n, &X, &Y);
        low 
= 0
        high 
= inf; 
        
for(i = 0; i < n; i++){
            scanf(
"%d%d", a+i, b+i);
            high 
= min(high, a[i] * X + b[i] * Y); 
        }
        
while(low <= high){
            mid 
= (low + high) >> 1
            
if(check(mid)) high = mid - 1
            
else low = mid + 1
        }
        printf(
"Case %d: %d\n", ca, high + 1);
    }
    
return 0;
}





tw 2011-01-21 16:44 鍙戣〃璇勮
]]>
hdu3434http://www.shnenglu.com/goAheadtw/articles/139032.htmltwtwFri, 21 Jan 2011 08:01:00 GMThttp://www.shnenglu.com/goAheadtw/articles/139032.htmlhttp://www.shnenglu.com/goAheadtw/comments/139032.htmlhttp://www.shnenglu.com/goAheadtw/articles/139032.html#Feedback0http://www.shnenglu.com/goAheadtw/comments/commentRss/139032.htmlhttp://www.shnenglu.com/goAheadtw/services/trackbacks/139032.html棰樼洰鏉ユ簮錛?http://acm.hdu.edu.cn/showproblem.php?pid=3434 

Sequence Adjustment

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 463    Accepted Submission(s): 144


Problem Description
Given a sequence consists of N integers. Each time you can choose a continuous subsequence and add 1 or minus 1 to the numbers in the subsequence .You task is to make all the numbers the same with
the least tries. You should calculate the number of the least tries
you needed and the number of different final sequences with the least tries.
 


 

Input
In the first line there is an integer T, indicates the number of test cases.(T<=30)
In each case, the first line contain one integer N(1<=N<=10^6),
the second line contain N integers and each integer in the sequence is between [1,10^9].
There may be some blank lines between each case.
 


 

Output
For each test case , output “Case d: x y “ where d is the case number
counted from one, x is the number of the least tries you need and y
is the number of different final sequences with the least tries.
 


 

Sample Input
2 2 2 4 6 1 1 1 2 2 2
 


 

Sample Output
Case 1: 2 3 Case 2: 1 2
Hint
In sample 1, we can add 1 twice at index 1 to get {4,4},or minus 1 twice at index 2 to get {2,2}, or we can add 1 once at index 1 and minus 1 once at index 2 to get {3,3}. So there are three different final sequences.
 


 

Author
wzc1989
 


 

Source


/*
鏇磋灝界殑瑙i鎶ュ憡瑙侊細(xì)
http://hi.baidu.com/liwang112358/blog/item/3dac7e566f300f55d0090679.html 
*/
#include <stdio.h>
#include <memory>
#include <iostream>
#include <algorithm>
#include <cstring>
#include <vector>
#include <map>
#include <cmath>
#include <set>
#include <queue>
#include <time.h>
#include <limits>
using namespace std;
#define N 1000005
#define ll long long
#define ABS(a) (a > 0 ? a : -a)
ll a[N], p[N];
int main(){
#ifndef ONLINE_JUDGE
 freopen("in.txt", "r", stdin);
 //freopen("out.txt", "w", stdout);
#endif
 int t, n, ca;
 ca = a[0] = p[0] = p[1] = 0;
 scanf("%d", &t);
 while(t--){
  scanf("%d", &n);
  int i, j;
  ll sum, ans;
  for(i = 1; i <= n; i++) scanf("%d", a+i);
  for(i = 2, j = 1; i <= n; i++){
   if(a[i] != a[j]){
    a[++j] = a[i];
    p[j] = a[j] - a[j - 1];
   }
  }
  n = j;
  ans = sum = 0;
  for(i = 2; i <= n; i++){
   if(p[i] * sum < 0) ans += min(ABS(sum), ABS(p[i]));
   sum += p[i];
  }
  sum = ABS(sum);
  ans += sum;
  //printf("Case %d: %lld %lld\n", ++ca, ans, sum + 1);
  printf("Case %d: %I64d %I64d\n", ++ca, ans, sum + 1);
 }
 return 0;
}

 

 



tw 2011-01-21 16:01 鍙戣〃璇勮
]]>
hdu3596(閫嗘嘗鍏拌〃杈懼紡姹傚?http://www.shnenglu.com/goAheadtw/articles/138607.htmltwtwSun, 16 Jan 2011 11:58:00 GMThttp://www.shnenglu.com/goAheadtw/articles/138607.htmlhttp://www.shnenglu.com/goAheadtw/comments/138607.htmlhttp://www.shnenglu.com/goAheadtw/articles/138607.html#Feedback0http://www.shnenglu.com/goAheadtw/comments/commentRss/138607.htmlhttp://www.shnenglu.com/goAheadtw/services/trackbacks/138607.html/*************************************/
/*鏀寔鏁板瓧(鑰岄潪琛ㄨ揪寮?鍓嶉潰鏈夋璐熷彿   */
/*鏀寔嫻偣鏁扮殑+錛?錛?錛?,^ 榪愮畻      */
/*************************************/
#include <stdio.h>
#include <memory>
#include <iostream>
#include <algorithm>
#include <cstring>
#include <vector>
#include <map>
#include <cmath>
#include <set>
#include <queue>
#include <time.h>
#include <limits>
#include <stack>
using namespace std;
#define N 10005
#define eps 1e-9
#define vType double
struct node{
 vType val;
 char op;
 node(vType _val=0, char _op = ' '):val(_val), op(_op){}
}nodes[N];
char str[N];
inline bool isDigit(char ch){
 return ch >= '0' && ch <= '9';
}
map<char, int> ms;
void init(){
 ms['('] = 0;
 ms['-'] = ms['+'] = 1;
 ms['*'] = ms['/'] = 2;
 ms['^'] = 3;
}
vType calPoland(node* nodes, int k){
 int i, j;
 vType a, b;
 stack<vType> s;
 for(i = 0; i < k; i++){
  if(nodes[i].op == ' '){
   s.push(nodes[i].val);
  }else{
   a = s.top();
   s.pop();
   b = s.top();
   s.pop();
   switch(nodes[i].op){
    case '+':
     s.push(b + a);
     break;
    case '-':
     s.push(b - a);
     break;
    case '*':
     s.push(b * a);
     break;
    case '/':
     if(fabs(a) < eps) throw true;
     s.push(b / a);
     break;
    case '^':
     s.push(pow(b, a));
     break;
   }
  }
 }
 return s.top();
}
vType poland(char* str){
 int i, k, sign;
 bool inNum, hasDot;  //inNum鏍囪褰撳墠鏄惁鍙互杈撳叆鏁板瓧, hasDot鏍囪鏄惁宸茬粡杈撳叆灝忔暟鐐?br> stack<char> oper;
 for(i = k = 0, sign = 1, inNum = true; str[i]; i++){
  if(isDigit(str[i]) || str[i] == '.'){
   if(inNum){
    vType val;
    double w = 1;
    if(str[i] == '.'){
     hasDot = true;
     val = 0;
    }
    else{
     val = str[i] - '0';
     hasDot = false;
    }
    i++;
    while(isDigit(str[i]) || str[i] == '.'){
     if(str[i] == '.'){
      if(hasDot) throw true;
      hasDot = true;
     }else{
      if(hasDot){
       w *= 0.1;
       val += (str[i] - '0') * w;
      }
      else val = val * 10 + str[i] - '0';
     }
     i++;
    }
    i--;
    nodes[k++] = node(val * sign, ' ');
    sign = 1;
    inNum = false;
   }else throw true;
  }else{
   switch(str[i]){
    case '(':
     oper.push(str[i]);
     break;
    case ')':
     while(!oper.empty() && oper.top() != '('){
      nodes[k++] = node(0, oper.top());
      oper.pop();
     }
     if(oper.empty()) throw true;  //娌℃湁涓?)'鍖歸厤鐨?('
     oper.pop();
     break;
    case '+':
    case '-':
    case '*':
    case '/':
    case '^':
     if(inNum){
      if(str[i] != '+' && str[i] != '-') throw true;
      while(str[i] == '+' || str[i] == '-'){
       if(str[i] == '-') sign *= -1;
       i++;
      }
      i--;
     }else{
      //while(!oper.empty() && ((str[i] != '^' && ms[str[i]] <= ms[oper.top()]) ||
      // ((str[i] == '^' && ms[str[i]] < ms[oper.top()])))){ //濡傛灉^鏄彸緇撳悎鐨勮瘽灝辯敤榪欎釜
      while(!oper.empty() && ms[str[i]] <= ms[oper.top()]){
        nodes[k++] = node(0, oper.top());
        oper.pop();
      }
      oper.push(str[i]);
      inNum = true;
     }
     break;
   }
  }
 }
 while(!oper.empty()){
  nodes[k++] = node(0, oper.top());
  oper.pop();
 }
 return calPoland(nodes, k);
}
void Cal(char* str){
 try{
  vType ans = poland(str);
  printf("%.8lf\n", ans);
 }
 catch(bool){
  printf("The teacher is so lazy!\n");
 }
}
int main(){
#ifndef ONLINE_JUDGE
 //freopen("in.txt", "r", stdin);
 //freopen("out.txt", "w", stdout);
#endif
 init();
 while(~scanf("%s", str)) Cal(str);
 return 0;
}


tw 2011-01-16 19:58 鍙戣〃璇勮
]]>
hdu 3624 錛堢畻鏈〃杈懼紡姹傚鹼級(jí)http://www.shnenglu.com/goAheadtw/articles/138553.htmltwtwFri, 14 Jan 2011 17:43:00 GMThttp://www.shnenglu.com/goAheadtw/articles/138553.htmlhttp://www.shnenglu.com/goAheadtw/comments/138553.htmlhttp://www.shnenglu.com/goAheadtw/articles/138553.html#Feedback0http://www.shnenglu.com/goAheadtw/comments/commentRss/138553.htmlhttp://www.shnenglu.com/goAheadtw/services/trackbacks/138553.html/*
1銆佸乏閫掑綊鍙互鐢ㄥ驚鐜潵瀹炵幇錛屽彸閫掑綊鍙互鐢ㄩ掑綊瀹炵幇(涔熷彲浠ョ敤寰幆瀹炵幇,涓嶈繃閫掑綊瀹炵幇璧鋒潵姣旇緝綆鍗?
2銆佸乏閫掑綊瀹炵幇宸︾粨鍚堣繍綆楋紝鍙抽掑綊瀹炵幇鍙崇粨鍚堣繍綆?br>hdu 3624(緗戝潃錛?http://acm.hdu.edu.cn/showproblem.php?pid=3624 ) 鐨勬枃娉?br>exp         -> addTerm | exp addOp addTerm
addOp    -> + | -
addTerm -> mulTerm | addTerm mulOp mulTerm
mulOp     -> * | / | %
mulTerm -> eTerm ^ mulTerm | eTerm
eTerm    ->sNum | (exp)
sNum     -> num | -eTerm
*/
#include <stdio.h>
#include <memory>
#include <iostream>
#include <algorithm>
#include <cstring>
#include <vector>
#include <map>
#include <cmath>
#include <set>
#include <queue>
#include <time.h>
#include <limits>
using namespace std;
#define vType long long
#define MAXLEN 2005
const int vMax = 0x7fffffff;
const int vMin = ~vMax;
#define checkVal(val) (val >= vMin && val <= vMax)
char str[MAXLEN];
int pos, cnt; //pos涓哄綋鍓嶆壂鎻忎綅緗紝cnt涓哄凡緇忓垎閰嶇殑鑺傜偣鐨勬暟鐩?br>char ch;  //ch涓哄綋鍓嶆壂鎻忕殑瀛楃
struct treeNode{
    char op, flag; 
    vType val;
    treeNode* ch[2];
    void setFlag(){
        if((ch[0] && !ch[0]->flag) || (ch[1] && !ch[1]->flag)){
            flag = false;
        }
    }
}mem[MAXLEN*10];
treeNode* exp();
inline bool isDigit(char ch){
    return ch >= '0' && ch <= '9';
}
inline treeNode* newNode(){
    mem[cnt].flag = true;
    mem[cnt].op = ' ';  //op涓虹┖鏍艱〃紺轟笉闇瑕佽繍綆?br>    mem[cnt].ch[0] = mem[cnt].ch[1] = NULL;
    return &mem[cnt++];
}
treeNode* getSyntaxTree(){
    treeNode* tree;
    pos = cnt = 0;
    int i, j;
    i = j = 0;
    ch = '\n';
    do{  //蹇界暐絀烘牸
        if(str[i] != ' ') str[j++] = str[i];
    }while(str[i++]);
 for(i = j = 0; str[i]; i++){ //鍔犺繖涓姝ユ槸涓轟簡(jiǎn)澶勭悊2000涓?鐨勫彉鎬佹暟鎹?br>  if(str[i] == '(') j++;
  else if(str[i] == ')') j--;
 }
 if(j != 0){
  tree = newNode();
  tree->flag = false;
 }else tree = exp();
    return tree;
}
treeNode* eTerm(){
    treeNode* t;
    t = newNode();
    ch = str[pos++];
    if(ch == '('){
        t = exp();
        if(ch != ')') t->flag = false;
        else ch = str[pos++];
    }else if(isDigit(ch)){
        vType a = ch - '0';
        for(ch = str[pos++];isDigit(ch); ch = str[pos++]){
            if(t->flag){
                a = a * 10 + ch - '0';
            }
            if(!checkVal(a)){
                t->flag = false;
            }
        }
  t->val = a;
 }else if(ch == '-'){
  t->op = ch;
  t->ch[0] = newNode();
  t->ch[0]->val = 0;
  t->ch[1] = eTerm();
  t->setFlag();
 }else t->flag = false;
    return t;
}
treeNode* mulTerm(){
    treeNode *t, *p, *r, *t0, *t1;;
    r = t = eTerm();
 p = NULL;
    while(ch == '^'){ //寰幆瀹炵幇鍙抽掑綊鏂囨硶
  t1 = newNode();
  t1->op = ch;
  t1->ch[0] = t;
  t0 = eTerm();
  t1->ch[1] = t0;
  if(p){
   p->ch[1] = t1;
  }else r = t1;
  p = t1;
  t = t0;
    }
    return r;
}
treeNode* addTerm(){
    treeNode *t, *p;
    t = newNode();
    t->ch[0] = mulTerm();
    t->setFlag();
    while(ch == '*' || ch == '/' || ch == '%'){
        t->op = ch;
        t->ch[1] = mulTerm();
        t->setFlag();
        p = t;
        t = newNode();
        t->ch[0] = p;
    }
    return t;
}
treeNode* exp(){
    treeNode *t, *p;
    t = newNode();
    t->ch[0] = addTerm();
    while(ch == '-' || ch == '+'){
        t->op = ch;
        t->ch[1] = addTerm();
        p = t;
        t = newNode();
        t->ch[0] = p;
    }
    return t;
}
void cal(treeNode* root){
    if(!root) return;
    cal(root->ch[0]);
    cal(root->ch[1]);
    root->setFlag();
    if(!root->flag) return;
    if(root->op != ' '){
        vType a = 0;
        switch(root->op){
            case '-':
                a = root->ch[0]->val - root->ch[1]->val;
                break;
            case '+':
                a = root->ch[0]->val + root->ch[1]->val;
                break;
            case '*':
                a = root->ch[0]->val * root->ch[1]->val;
                break;
            case '/':
                if(root->ch[1]->val == 0){
                    root->flag = false;
                    return;
                }
                a = root->ch[0]->val / root->ch[1]->val;
                break;
            case '%':
                if(root->ch[1]->val == 0){
                    root->flag = 0;
                    return;
                }
                a = root->ch[0]->val % root->ch[1]->val;
                break;
            case '^':
    if(root->ch[1]->val < 0 || (root->ch[0]->val == 0 && root->ch[1]->val == 0)){
                    root->flag = false;
                    return;
                }
                double b = pow((double)root->ch[0]->val, (double)root->ch[1]->val);
                if(checkVal(b)) a = (vType)b;
                else{
                    root->flag = false;
                    return;
                }
                break;
        }
  if(checkVal(a)){
   root->val = a;
   root->setFlag();
  }else{
   root->flag = false;
  }
    }else if(root->ch[0]){
        root->flag = root->ch[0]->flag;
        root->val = root->ch[0]->val;
    }
}
int main(){
#ifndef ONLINE_JUDGE
 //freopen("in.txt", "r", stdin);
    //freopen("out.txt", "w", stdout);
#endif
    int i, c;
    treeNode* root;
    scanf("%d", &c);
    getchar();
    for(i = 1; i <= c; i++){
        gets(str);
        root = getSyntaxTree();
        printf("Case %d: ", i);
        cal(root);
  if(root->flag){
   printf("%I64d\n", root->val);
  }
        else printf("ERROR!\n");
    }
    return 0;
}

 



tw 2011-01-15 01:43 鍙戣〃璇勮
]]>
青青草原综合久久大伊人导航_色综合久久天天综合_日日噜噜夜夜狠狠久久丁香五月_热久久这里只有精品
  • <ins id="pjuwb"></ins>
    <blockquote id="pjuwb"><pre id="pjuwb"></pre></blockquote>
    <noscript id="pjuwb"></noscript>
          <sup id="pjuwb"><pre id="pjuwb"></pre></sup>
            <dd id="pjuwb"></dd>
            <abbr id="pjuwb"></abbr>
            亚洲国产中文字幕在线观看| 亚洲国产精品一区在线观看不卡| 中文亚洲欧美| 亚洲视频axxx| 国产精品亚洲人在线观看| 香蕉久久夜色精品| 久久精品成人欧美大片古装| 1024日韩| 亚洲精品一品区二品区三品区| 欧美性猛交视频| 久久成人一区| 蜜臀va亚洲va欧美va天堂| 亚洲免费成人av电影| 亚洲先锋成人| 宅男噜噜噜66一区二区| 国产精品视频福利| 久久综合色一综合色88| 欧美激情在线观看| 欧美专区中文字幕| 欧美成人久久| 久久福利一区| 欧美日韩成人综合天天影院| 欧美在线视频全部完| 久久综合狠狠综合久久激情| 亚洲图片欧美午夜| 久久久久久久国产| 亚洲欧美在线网| 女主播福利一区| 久久精品国产99国产精品澳门| 免费短视频成人日韩| 亚洲欧美电影在线观看| 男男成人高潮片免费网站| 亚洲欧美日本精品| 欧美高清视频一区二区| 欧美在线免费观看视频| 欧美日韩成人激情| 欧美成人三级在线| 国产日韩欧美综合在线| 亚洲毛片在线观看.| 亚洲成人影音| 午夜欧美精品久久久久久久| 一区二区久久久久| 欧美超级免费视 在线| 久久久国产精品一区二区三区| 欧美日韩亚洲一区二区| 亚洲国产精品黑人久久久| 国产欧美日韩综合一区在线观看| 日韩一区二区精品在线观看| 亚洲国内自拍| 久久综合五月天婷婷伊人| 久久aⅴ国产欧美74aaa| 欧美亚韩一区| 99日韩精品| 99视频热这里只有精品免费| 蜜臀久久久99精品久久久久久| 久久久精彩视频| 国产麻豆精品视频| 亚洲资源av| 香蕉久久国产| 国产欧美一区二区三区另类精品| 亚洲视频久久| 亚洲欧美中文在线视频| 国产精品麻豆欧美日韩ww | 亚洲激情视频| 麻豆国产精品777777在线| 麻豆成人av| 禁断一区二区三区在线| 久久不见久久见免费视频1| 久久久7777| 激情欧美一区二区三区在线观看| 久久精品视频在线播放| 久久亚洲精品网站| 亚洲福利av| 欧美激情国产日韩精品一区18| 亚洲国产另类久久精品| 99精品国产热久久91蜜凸| 欧美日韩福利视频| 亚洲一品av免费观看| 欧美在线www| 黄网动漫久久久| 久久青草福利网站| 亚洲国产精品久久久久秋霞影院| 亚洲精品免费一二三区| 欧美婷婷久久| 欧美一级黄色录像| 欧美成人久久| 亚洲免费在线播放| 国产在线欧美日韩| 欧美成人一品| 亚洲天堂成人在线视频| 久久婷婷丁香| 一本到高清视频免费精品| 国产农村妇女毛片精品久久麻豆| 久久久国产成人精品| 亚洲欧洲一级| 久久久精品一品道一区| 亚洲开发第一视频在线播放| 国产精品色网| 欧美国产日韩一区二区| 亚洲视频欧美视频| 男人插女人欧美| 亚洲欧美成人综合| 亚洲人成人77777线观看| 国产精品男人爽免费视频1| 久久免费视频一区| 亚洲午夜精品17c| 欧美国产一区视频在线观看| 先锋影音网一区二区| 亚洲人成人99网站| 国产色产综合产在线视频| 欧美国产视频在线观看| 欧美在线视屏| 亚洲午夜日本在线观看| 亚洲日产国产精品| 每日更新成人在线视频| 午夜精品av| 一区二区三区日韩在线观看| 在线观看日韩精品| 国产视频一区欧美| 欧美性片在线观看| 欧美另类亚洲| 免费成人高清| 久久久国产精品一区二区中文| 亚洲天堂免费观看| 一本大道久久精品懂色aⅴ| 亚洲成色777777女色窝| 精品二区视频| 国产麻豆午夜三级精品| 国产精品高清网站| 欧美精彩视频一区二区三区| 美女国产一区| 另类激情亚洲| 久热精品视频在线观看一区| 欧美中文在线观看| 欧美在线二区| 久久九九全国免费精品观看| 午夜在线视频观看日韩17c| 亚洲影音一区| 亚洲一区精品视频| 亚洲自拍三区| 亚洲欧美成人| 欧美一区二区在线观看| 欧美一二三区精品| 久久精品国产亚洲5555| 久久精品亚洲热| 久久网站免费| 欧美插天视频在线播放| 欧美国产日韩视频| 欧美日韩国产小视频在线观看| 欧美日韩播放| 国产精品爽爽爽| 国产专区精品视频| 亚洲成色www8888| 亚洲经典自拍| 亚洲午夜精品久久| 欧美亚洲系列| 男女激情久久| 日韩视频在线观看国产| 亚洲午夜久久久久久久久电影院 | 久久精品视频在线| 久久综合999| 欧美理论大片| 国产精品老牛| 国产亚洲欧美一级| 亚洲经典在线看| 亚洲一区二区不卡免费| 久久成人18免费观看| 欧美成人中文字幕| 9l国产精品久久久久麻豆| 午夜在线成人av| 欧美成人一区在线| 国产精品性做久久久久久| 在线免费观看视频一区| 在线视频精品一| 久久久水蜜桃av免费网站| 亚洲欧洲日夜超级视频| 欧美亚洲自偷自偷| 欧美激情在线播放| 国产午夜亚洲精品不卡| 亚洲美女中出| 在线视频亚洲一区| 久久人人爽人人| 欧美激情区在线播放| 一道本一区二区| 久久久亚洲精品一区二区三区 | 亚洲乱亚洲高清| 欧美尤物一区| 欧美日韩精品三区| 精品91视频| 亚洲欧美日韩爽爽影院| 亚洲丰满在线| 欧美影院视频| 国产精品美女久久久久久2018| 亚洲激情成人在线| 久久免费视频在线观看| 亚洲视频在线视频| 欧美日韩成人综合| 亚洲精品国产精品乱码不99| 久久欧美肥婆一二区| 亚洲综合日韩在线|