锘??xml version="1.0" encoding="utf-8" standalone="yes"?>亚洲综合视频1区,亚洲欧美日韩另类,欧美丝袜一区二区http://m.shnenglu.com/goAheadtw/category/15891.htmlhahazh-cnWed, 02 Feb 2011 02:09:05 GMTWed, 02 Feb 2011 02:09:05 GMT60hdu3440(宸垎綰︽潫)http://m.shnenglu.com/goAheadtw/articles/139140.htmltwtwSat, 22 Jan 2011 17:13:00 GMThttp://m.shnenglu.com/goAheadtw/articles/139140.htmlhttp://m.shnenglu.com/goAheadtw/comments/139140.htmlhttp://m.shnenglu.com/goAheadtw/articles/139140.html#Feedback0http://m.shnenglu.com/goAheadtw/comments/commentRss/139140.htmlhttp://m.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://m.shnenglu.com/goAheadtw/articles/139120.htmltwtwSat, 22 Jan 2011 08:58:00 GMThttp://m.shnenglu.com/goAheadtw/articles/139120.htmlhttp://m.shnenglu.com/goAheadtw/comments/139120.htmlhttp://m.shnenglu.com/goAheadtw/articles/139120.html#Feedback0http://m.shnenglu.com/goAheadtw/comments/commentRss/139120.htmlhttp://m.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://m.shnenglu.com/goAheadtw/articles/139038.htmltwtwFri, 21 Jan 2011 08:44:00 GMThttp://m.shnenglu.com/goAheadtw/articles/139038.htmlhttp://m.shnenglu.com/goAheadtw/comments/139038.htmlhttp://m.shnenglu.com/goAheadtw/articles/139038.html#Feedback0http://m.shnenglu.com/goAheadtw/comments/commentRss/139038.htmlhttp://m.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://m.shnenglu.com/goAheadtw/articles/139032.htmltwtwFri, 21 Jan 2011 08:01:00 GMThttp://m.shnenglu.com/goAheadtw/articles/139032.htmlhttp://m.shnenglu.com/goAheadtw/comments/139032.htmlhttp://m.shnenglu.com/goAheadtw/articles/139032.html#Feedback0http://m.shnenglu.com/goAheadtw/comments/commentRss/139032.htmlhttp://m.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://m.shnenglu.com/goAheadtw/articles/138607.htmltwtwSun, 16 Jan 2011 11:58:00 GMThttp://m.shnenglu.com/goAheadtw/articles/138607.htmlhttp://m.shnenglu.com/goAheadtw/comments/138607.htmlhttp://m.shnenglu.com/goAheadtw/articles/138607.html#Feedback0http://m.shnenglu.com/goAheadtw/comments/commentRss/138607.htmlhttp://m.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://m.shnenglu.com/goAheadtw/articles/138553.htmltwtwFri, 14 Jan 2011 17:43:00 GMThttp://m.shnenglu.com/goAheadtw/articles/138553.htmlhttp://m.shnenglu.com/goAheadtw/comments/138553.htmlhttp://m.shnenglu.com/goAheadtw/articles/138553.html#Feedback0http://m.shnenglu.com/goAheadtw/comments/commentRss/138553.htmlhttp://m.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>
            一区二区三区在线观看国产| 国产精品v一区二区三区| 麻豆av一区二区三区久久| 欧美主播一区二区三区美女 久久精品人| 亚洲经典在线看| 久久精品综合一区| 毛片一区二区| 亚洲国产精彩中文乱码av在线播放| 在线观看免费视频综合| 国语自产精品视频在线看| 免费视频最近日韩| 欧美成年人视频网站| 午夜精品国产| 久久久九九九九| 欧美日本韩国一区| 国产一区成人| 日韩午夜免费视频| 欧美尤物一区| 亚洲第一色中文字幕| 亚洲图片欧美一区| 久久综合伊人| 国产美女精品视频免费观看| 亚洲第一久久影院| 午夜在线一区| 最新日韩在线视频| 久久精品二区| 欧美视频四区| 91久久久久| 久久久不卡网国产精品一区| 91久久夜色精品国产网站| 欧美一区二区三区视频免费| 欧美日韩另类字幕中文| 伊人春色精品| 在线观看成人一级片| 一区二区三区视频在线看| 亚洲精品中文在线| 久久国产精品久久精品国产| 亚洲精选91| 欧美sm极限捆绑bd| 黄色成人av网| 久久国产欧美日韩精品| 久久精品国产视频| 欧美一区二区三区的| 亚洲福利在线看| 久久久精品五月天| 国产一区二区三区在线观看免费| 国产日韩精品在线观看| 亚洲一本大道在线| 亚洲一区二区三区在线| 午夜视频在线观看一区二区三区| 国产精品国产三级国产专播精品人 | 六十路精品视频| 一本色道久久88综合日韩精品| 亚洲免费不卡| 久久久久久久成人| 在线观看一区二区视频| 久久久夜夜夜| 欧美国产日韩亚洲一区| 亚洲国产另类 国产精品国产免费| 亚洲高清一区二| 一二美女精品欧洲| 欧美精品系列| 中文一区在线| 亚洲影院色无极综合| 久久视频免费观看| 狠狠色狠狠色综合日日五| 亚洲美女色禁图| 亚洲欧洲精品成人久久奇米网| 亚洲视频电影在线| 欧美性色aⅴ视频一区日韩精品| 国产午夜精品全部视频播放 | 亚洲日本国产| 亚洲高清三级视频| 欧美日韩一区视频| 午夜精品免费在线| 久久超碰97人人做人人爱| 在线成人性视频| 91久久一区二区| 国产精品久久久久9999吃药| 亚洲欧美在线免费| 亚洲成色www8888| 欧美精品v日韩精品v国产精品| 国产日本精品| 久久综合五月天婷婷伊人| 免费久久99精品国产自| 亚洲网站在线| 久久人人97超碰国产公开结果| 欧美视频一区| 欧美中文字幕精品| 欧美成人亚洲成人日韩成人| 亚洲午夜av电影| 久久久www| 亚洲综合精品一区二区| 久久久www成人免费精品| 国产精品综合| 欧美激情精品久久久久久久变态 | 亚洲午夜影视影院在线观看| 国产精品中文字幕欧美| 亚洲一区在线播放| 久久精品视频在线| 亚洲电影免费在线| 欧美一区二区三区在线看| 欧美有码在线观看视频| 亚洲国产免费看| 亚洲婷婷国产精品电影人久久| 麻豆国产精品va在线观看不卡| 国产精品久久久久aaaa九色| 亚洲国产精品女人久久久| 亚洲精品久久久久久一区二区| 麻豆成人综合网| 亚洲国产精品va在线看黑人动漫 | 亚洲女ⅴideoshd黑人| 在线不卡中文字幕| 亚洲一区欧美激情| 国产欧美精品在线| 亚洲成色777777在线观看影院| 美腿丝袜亚洲色图| 亚洲电影免费观看高清完整版在线观看 | 欧美日韩在线视频观看| 麻豆国产精品777777在线| 国产精品免费小视频| 亚洲精品欧洲| 日韩视频免费| 亚洲午夜在线观看| 一区二区免费看| 欧美福利网址| 欧美激情一区三区| 1000部精品久久久久久久久| 午夜一区二区三区不卡视频| 国产日韩在线视频| 亚洲在线视频观看| 香蕉久久夜色| 国产精品亚洲成人| 亚洲午夜免费福利视频| 亚洲欧美成人综合| 国产精品女人毛片| 亚洲欧美日韩国产成人| 激情六月综合| 久久久国际精品| 免费中文字幕日韩欧美| 欧美福利视频网站| 午夜在线视频观看日韩17c| 欧美日韩日本视频| 在线视频日韩| 欧美在线观看网站| 极品裸体白嫩激情啪啪国产精品 | 性伦欧美刺激片在线观看| 在线观看视频日韩| 久久久蜜桃精品| 欧美激情一区二区三区全黄| 136国产福利精品导航网址应用| 蜜臀久久99精品久久久画质超高清 | 亚洲午夜伦理| 欧美日韩一区在线播放| 99re在线精品| 欧美一区二区三区另类| 国产一区二区成人久久免费影院| 亚洲第一精品夜夜躁人人爽| 1024成人网色www| 欧美理论电影在线观看| 一区二区久久| 亚洲欧洲一区二区天堂久久| 一区二区不卡在线视频 午夜欧美不卡在 | 99精品欧美一区| 欧美在线黄色| 免费成人高清视频| 99亚洲一区二区| 国产欧美日韩综合一区在线观看| 亚洲欧洲一区二区在线播放| 国产精品一区二区你懂的| 欧美亚洲一区二区在线观看| 你懂的视频欧美| 亚洲欧美另类中文字幕| 亚洲成人资源| 国产精品综合网站| 欧美激情中文不卡| 亚洲国产精品v| 午夜亚洲性色福利视频| 亚洲成色www8888| 国产精品一页| 欧美伦理在线观看| 久久人人超碰| 亚洲男人的天堂在线观看| 亚洲国产精品久久久久秋霞蜜臀| 亚洲大片免费看| 久久高清国产| 夜夜爽99久久国产综合精品女不卡| 亚洲精品欧美日韩专区| 国产精品日韩在线观看| 欧美精品亚洲精品| 每日更新成人在线视频| 欧美亚洲视频在线观看| 一本色道久久综合亚洲二区三区 | 欧美激情在线| 欧美一区不卡| 亚洲欧美成人综合| 亚洲一区二区在线免费观看| 亚洲精品一区中文| 91久久极品少妇xxxxⅹ软件| 欧美成va人片在线观看|