From 596be6ae110eac7ee22a2b0288e4dc666c8a7bbc Mon Sep 17 00:00:00 2001 From: KiritoTRw <3021577574@qq.com> Date: Sat, 10 Sep 2016 11:36:30 +0800 Subject: [PATCH] Powered By HC TECH : AutoACer Engine 5000-5099 --- HDOJ/5000_autoAC.cpp | 39 +++++++ HDOJ/5001_autoAC.cpp | 62 +++++++++++ HDOJ/5002_autoAC.cpp | 205 ++++++++++++++++++++++++++++++++++++ HDOJ/5003_autoAC.cpp | 40 +++++++ HDOJ/5004_autoAC.cpp | 102 ++++++++++++++++++ HDOJ/5005_autoAC.cpp | 134 ++++++++++++++++++++++++ HDOJ/5006_autoAC.cpp | 90 ++++++++++++++++ HDOJ/5007_autoAC.cpp | 35 +++++++ HDOJ/5008_autoAC.cpp | 151 +++++++++++++++++++++++++++ HDOJ/5009_autoAC.cpp | 89 ++++++++++++++++ HDOJ/5010_autoAC.cpp | 223 +++++++++++++++++++++++++++++++++++++++ HDOJ/5011_autoAC.cpp | 29 ++++++ HDOJ/5012_autoAC.cpp | 93 +++++++++++++++++ HDOJ/5013_autoAC.cpp | 69 +++++++++++++ HDOJ/5014_autoAC.cpp | 47 +++++++++ HDOJ/5015_autoAC.cpp | 89 ++++++++++++++++ HDOJ/5016_autoAC.cpp | 156 ++++++++++++++++++++++++++++ HDOJ/5017_autoAC.cpp | 57 ++++++++++ HDOJ/5018_autoAC.cpp | 41 ++++++++ HDOJ/5019_autoAC.cpp | 42 ++++++++ HDOJ/5020_autoAC.cpp | 55 ++++++++++ HDOJ/5021_autoAC.cpp | 106 +++++++++++++++++++ HDOJ/5022_autoAC.cpp | 125 ++++++++++++++++++++++ HDOJ/5023_autoAC.cpp | 86 +++++++++++++++ HDOJ/5024_autoAC.cpp | 65 ++++++++++++ HDOJ/5025_autoAC.cpp | 134 ++++++++++++++++++++++++ HDOJ/5027_autoAC.cpp | 137 ++++++++++++++++++++++++ HDOJ/5029_autoAC.cpp | 187 +++++++++++++++++++++++++++++++++ HDOJ/5030_autoAC.cpp | 113 ++++++++++++++++++++ HDOJ/5031_autoAC.cpp | 231 +++++++++++++++++++++++++++++++++++++++++ HDOJ/5032_autoAC.cpp | 88 ++++++++++++++++ HDOJ/5033_autoAC.cpp | 146 ++++++++++++++++++++++++++ HDOJ/5035_autoAC.cpp | 24 +++++ HDOJ/5036_autoAC.cpp | 42 ++++++++ HDOJ/5037_autoAC.cpp | 42 ++++++++ HDOJ/5038_autoAC.cpp | 67 ++++++++++++ HDOJ/5039_autoAC.cpp | 141 +++++++++++++++++++++++++ HDOJ/5040_autoAC.cpp | 134 ++++++++++++++++++++++++ HDOJ/5042_autoAC.cpp | 135 ++++++++++++++++++++++++ HDOJ/5043_autoAC.cpp | 90 ++++++++++++++++ HDOJ/5044_autoAC.cpp | 219 +++++++++++++++++++++++++++++++++++++++ HDOJ/5045_autoAC.cpp | 52 ++++++++++ HDOJ/5046_autoAC.cpp | 148 ++++++++++++++++++++++++++ HDOJ/5047_autoAC.cpp | 25 +++++ HDOJ/5048_autoAC.cpp | 182 ++++++++++++++++++++++++++++++++ HDOJ/5049_autoAC.cpp | 241 +++++++++++++++++++++++++++++++++++++++++++ HDOJ/5050_autoAC.cpp | 106 +++++++++++++++++++ HDOJ/5051_autoAC.cpp | 55 ++++++++++ HDOJ/5052_autoAC.cpp | 186 +++++++++++++++++++++++++++++++++ HDOJ/5053_autoAC.cpp | 28 +++++ HDOJ/5054_autoAC.cpp | 15 +++ HDOJ/5055_autoAC.cpp | 48 +++++++++ HDOJ/5056_autoAC.cpp | 64 ++++++++++++ HDOJ/5057_autoAC.cpp | 65 ++++++++++++ HDOJ/5058_autoAC.cpp | 47 +++++++++ HDOJ/5059_autoAC.cpp | 43 ++++++++ HDOJ/5060_autoAC.cpp | 66 ++++++++++++ HDOJ/5062_autoAC.cpp | 15 +++ HDOJ/5063_autoAC.cpp | 70 +++++++++++++ HDOJ/5064_autoAC.cpp | 52 ++++++++++ HDOJ/5065_autoAC.cpp | 51 +++++++++ HDOJ/5066_autoAC.cpp | 9 ++ HDOJ/5067_autoAC.cpp | 76 ++++++++++++++ HDOJ/5068_autoAC.cpp | 109 +++++++++++++++++++ HDOJ/5069_autoAC.cpp | 136 ++++++++++++++++++++++++ HDOJ/5071_autoAC.cpp | 148 ++++++++++++++++++++++++++ HDOJ/5072_autoAC.cpp | 95 +++++++++++++++++ HDOJ/5073_autoAC.cpp | 47 +++++++++ HDOJ/5074_autoAC.cpp | 48 +++++++++ HDOJ/5076_autoAC.cpp | 155 ++++++++++++++++++++++++++++ HDOJ/5077_autoAC.cpp | 18 ++++ HDOJ/5078_autoAC.cpp | 37 +++++++ HDOJ/5079_autoAC.cpp | 164 +++++++++++++++++++++++++++++ HDOJ/5080_autoAC.cpp | 165 +++++++++++++++++++++++++++++ HDOJ/5082_autoAC.cpp | 30 ++++++ HDOJ/5083_autoAC.cpp | 159 ++++++++++++++++++++++++++++ HDOJ/5084_autoAC.cpp | 46 +++++++++ HDOJ/5086_autoAC.cpp | 35 +++++++ HDOJ/5087_autoAC.cpp | 35 +++++++ HDOJ/5088_autoAC.cpp | 64 ++++++++++++ HDOJ/5089_autoAC.cpp | 78 ++++++++++++++ HDOJ/5090_autoAC.cpp | 64 ++++++++++++ HDOJ/5091_autoAC.cpp | 96 +++++++++++++++++ HDOJ/5092_autoAC.cpp | 55 ++++++++++ HDOJ/5093_autoAC.cpp | 81 +++++++++++++++ HDOJ/5094_autoAC.cpp | 71 +++++++++++++ HDOJ/5095_autoAC.cpp | 74 +++++++++++++ HDOJ/5096_autoAC.cpp | 164 +++++++++++++++++++++++++++++ HDOJ/5097_autoAC.cpp | 49 +++++++++ HDOJ/5098_autoAC.cpp | 106 +++++++++++++++++++ HDOJ/5099_autoAC.cpp | 72 +++++++++++++ 91 files changed, 8205 insertions(+) create mode 100644 HDOJ/5000_autoAC.cpp create mode 100644 HDOJ/5001_autoAC.cpp create mode 100644 HDOJ/5002_autoAC.cpp create mode 100644 HDOJ/5003_autoAC.cpp create mode 100644 HDOJ/5004_autoAC.cpp create mode 100644 HDOJ/5005_autoAC.cpp create mode 100644 HDOJ/5006_autoAC.cpp create mode 100644 HDOJ/5007_autoAC.cpp create mode 100644 HDOJ/5008_autoAC.cpp create mode 100644 HDOJ/5009_autoAC.cpp create mode 100644 HDOJ/5010_autoAC.cpp create mode 100644 HDOJ/5011_autoAC.cpp create mode 100644 HDOJ/5012_autoAC.cpp create mode 100644 HDOJ/5013_autoAC.cpp create mode 100644 HDOJ/5014_autoAC.cpp create mode 100644 HDOJ/5015_autoAC.cpp create mode 100644 HDOJ/5016_autoAC.cpp create mode 100644 HDOJ/5017_autoAC.cpp create mode 100644 HDOJ/5018_autoAC.cpp create mode 100644 HDOJ/5019_autoAC.cpp create mode 100644 HDOJ/5020_autoAC.cpp create mode 100644 HDOJ/5021_autoAC.cpp create mode 100644 HDOJ/5022_autoAC.cpp create mode 100644 HDOJ/5023_autoAC.cpp create mode 100644 HDOJ/5024_autoAC.cpp create mode 100644 HDOJ/5025_autoAC.cpp create mode 100644 HDOJ/5027_autoAC.cpp create mode 100644 HDOJ/5029_autoAC.cpp create mode 100644 HDOJ/5030_autoAC.cpp create mode 100644 HDOJ/5031_autoAC.cpp create mode 100644 HDOJ/5032_autoAC.cpp create mode 100644 HDOJ/5033_autoAC.cpp create mode 100644 HDOJ/5035_autoAC.cpp create mode 100644 HDOJ/5036_autoAC.cpp create mode 100644 HDOJ/5037_autoAC.cpp create mode 100644 HDOJ/5038_autoAC.cpp create mode 100644 HDOJ/5039_autoAC.cpp create mode 100644 HDOJ/5040_autoAC.cpp create mode 100644 HDOJ/5042_autoAC.cpp create mode 100644 HDOJ/5043_autoAC.cpp create mode 100644 HDOJ/5044_autoAC.cpp create mode 100644 HDOJ/5045_autoAC.cpp create mode 100644 HDOJ/5046_autoAC.cpp create mode 100644 HDOJ/5047_autoAC.cpp create mode 100644 HDOJ/5048_autoAC.cpp create mode 100644 HDOJ/5049_autoAC.cpp create mode 100644 HDOJ/5050_autoAC.cpp create mode 100644 HDOJ/5051_autoAC.cpp create mode 100644 HDOJ/5052_autoAC.cpp create mode 100644 HDOJ/5053_autoAC.cpp create mode 100644 HDOJ/5054_autoAC.cpp create mode 100644 HDOJ/5055_autoAC.cpp create mode 100644 HDOJ/5056_autoAC.cpp create mode 100644 HDOJ/5057_autoAC.cpp create mode 100644 HDOJ/5058_autoAC.cpp create mode 100644 HDOJ/5059_autoAC.cpp create mode 100644 HDOJ/5060_autoAC.cpp create mode 100644 HDOJ/5062_autoAC.cpp create mode 100644 HDOJ/5063_autoAC.cpp create mode 100644 HDOJ/5064_autoAC.cpp create mode 100644 HDOJ/5065_autoAC.cpp create mode 100644 HDOJ/5066_autoAC.cpp create mode 100644 HDOJ/5067_autoAC.cpp create mode 100644 HDOJ/5068_autoAC.cpp create mode 100644 HDOJ/5069_autoAC.cpp create mode 100644 HDOJ/5071_autoAC.cpp create mode 100644 HDOJ/5072_autoAC.cpp create mode 100644 HDOJ/5073_autoAC.cpp create mode 100644 HDOJ/5074_autoAC.cpp create mode 100644 HDOJ/5076_autoAC.cpp create mode 100644 HDOJ/5077_autoAC.cpp create mode 100644 HDOJ/5078_autoAC.cpp create mode 100644 HDOJ/5079_autoAC.cpp create mode 100644 HDOJ/5080_autoAC.cpp create mode 100644 HDOJ/5082_autoAC.cpp create mode 100644 HDOJ/5083_autoAC.cpp create mode 100644 HDOJ/5084_autoAC.cpp create mode 100644 HDOJ/5086_autoAC.cpp create mode 100644 HDOJ/5087_autoAC.cpp create mode 100644 HDOJ/5088_autoAC.cpp create mode 100644 HDOJ/5089_autoAC.cpp create mode 100644 HDOJ/5090_autoAC.cpp create mode 100644 HDOJ/5091_autoAC.cpp create mode 100644 HDOJ/5092_autoAC.cpp create mode 100644 HDOJ/5093_autoAC.cpp create mode 100644 HDOJ/5094_autoAC.cpp create mode 100644 HDOJ/5095_autoAC.cpp create mode 100644 HDOJ/5096_autoAC.cpp create mode 100644 HDOJ/5097_autoAC.cpp create mode 100644 HDOJ/5098_autoAC.cpp create mode 100644 HDOJ/5099_autoAC.cpp diff --git a/HDOJ/5000_autoAC.cpp b/HDOJ/5000_autoAC.cpp new file mode 100644 index 0000000..ee89dec --- /dev/null +++ b/HDOJ/5000_autoAC.cpp @@ -0,0 +1,39 @@ +#include +#include +#include +using namespace std ; +const int mod=1000000007 ; +int T[2005],dp[2005][2005] ; +int main() +{ + int t ; + scanf("%d",&t) ; + while(t--) + { + int n ; + scanf("%d",&n) ; + int sum=0 ; + for(int i=0 ;i>=1 ; + for(int i=1 ;i +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#define INF 1000000000000000010LL +#define ll long long +#define max3(a,b,c) max(a,max(b,c)) +using namespace std; +vector way[55]; +int cnt[55]; +double dp[10010][55]; +int main(){ + int t; + cin>>t; + while(t--){ + memset(way,0,sizeof(way)); + memset(cnt,0,sizeof(cnt)); + int n,m,d; + cin>>n>>m>>d; + for(int i=1;i<=m;i++){ + int u,v; + scanf("%d%d",&u,&v); + way[u].push_back(v); + way[v].push_back(u); + cnt[u]++; + cnt[v]++; + } + for(int i=1;i<=n;i++){ + dp[0][i]=(1.0/n); + } + for(int l=1;l<=n;l++){ + for(int i=1;i<=d;i++){ + for(int j=0;j<=n;j++)dp[i][j]=0.0; + } + for(int i=1;i<=d;i++){ + for(int j=1;j<=n;j++){ + if(j==l)continue; + for(int k=0;k +#include +#include +#include +using namespace std; +typedef long long LL; +#define FOR(i, n) for(int i = 0; i < n; ++i) +const int MAXV = 100010; +const int MAXE = MAXV << 1; +const int INF = 0x3f3f3f3f; +const int NINF = -INF; +struct LCT { + struct Node { + Node *ch[2], *fa; + int val, set, add; + int max[2], cnt[2], size; + bool rt, rev; + } statePool[MAXV], *nil; + int ncnt; + int head[MAXV], val[MAXV], ecnt; + int to[MAXE], next[MAXE]; + int n, m, T; + Node *ptr[MAXV]; + LCT() { + ptr[0] = nil = statePool; + nil->size = 0; + FOR(k, 2) nil->max[k] = NINF; + } + void init() { + memset(head + 1, -1, n * sizeof(int)); + ncnt = 1; + ecnt = 0; + } + void add_edge(int u, int v) { + to[ecnt] = v; next[ecnt] = head[u]; head[u] = ecnt++; + to[ecnt] = u; next[ecnt] = head[v]; head[v] = ecnt++; + } + Node* new_node(int val, Node *f) { + Node* x = &statePool[ncnt++]; + x->ch[0] = x->ch[1] = nil; x->fa = f; + x->val = val; x->set = NINF; x->add = 0; + x->max[0] = val; x->cnt[0] = 1; + x->max[1] = NINF; + x->size = 1; + x->rt = true; x->rev = false; + return x; + } + void dfs(int u, int f) { + ptr[u] = new_node(val[u], ptr[f]); + for(int p = head[u]; ~p; p = next[p]) { + int v = to[p]; + if(v == f) continue; + dfs(v, u); + } + } + void get_max(int &a, int &b, int c) { + if(a != c) { + if(b < c) swap(b, c); + if(a < b) swap(a, b); + } + } + void cnt_max(int a, int &cnt, int b, int bcnt) { + if(a != NINF && a == b) cnt += bcnt; + } + void update(Node *x) { + x->size = x->ch[0]->size + x->ch[1]->size + 1; + x->max[0] = x->val; x->max[1] = NINF; + FOR(i, 2) FOR(j, 2) + get_max(x->max[0], x->max[1], x->ch[i]->max[j]); + FOR(k, 2) x->cnt[k] = 0; + FOR(k, 2) cnt_max(x->max[k], x->cnt[k], x->val, 1); + FOR(k, 2) FOR(i, 2) FOR(j, 2) + cnt_max(x->max[k], x->cnt[k], x->ch[i]->max[j], x->ch[i]->cnt[j]); + } + void rotate(Node *x) { + Node *y = x->fa; + int t = (y->ch[1] == x); + if(y->rt) y->rt = false, x->rt = true; + else y->fa->ch[y->fa->ch[1] == y] = x; + x->fa = y->fa; + (y->ch[t] = x->ch[t ^ 1])->fa = y; + (x->ch[t ^ 1] = y)->fa = x; + update(y); + } + void update_set(Node *x, int val) { + if(x == nil) return ; + x->add = 0; + x->val = x->set = val; + x->max[0] = val; x->cnt[0] = x->size; + x->max[1] = NINF; + } + void update_add(Node *x, int val) { + if(x == nil) return ; + x->add += val; + x->val += val; + FOR(k, 2) if(x->max[k] != NINF) + x->max[k] += val; + } + void update_rev(Node *x) { + if(x == nil) return ; + x->rev = !x->rev; + swap(x->ch[0], x->ch[1]); + } + void pushdown(Node *x) { + if(x->set != NINF) { + FOR(k, 2) update_set(x->ch[k], x->set); + x->set = NINF; + } + if(x->add != 0) { + FOR(k, 2) update_add(x->ch[k], x->add); + x->add = 0; + } + if(x->rev) { + FOR(k, 2) update_rev(x->ch[k]); + x->rev = false; + } + } + void push(Node *x) { + if(!x->rt) push(x->fa); + pushdown(x); + } + void splay(Node *x) { + push(x); + while(!x->rt) { + Node *f = x->fa, *ff = f->fa; + if(!f->rt) rotate(((ff->ch[1] == f) && (f->ch[1] == x)) ? f : x); + rotate(x); + } + update(x); + } + Node* access(Node *x) { + Node *y = nil; + while(x != nil) { + splay(x); + x->ch[1]->rt = true; + (x->ch[1] = y)->rt = false; + update(x); + y = x; x = x->fa; + } + return y; + } + void be_root(Node *x) { + access(x); + splay(x); + update_rev(x); + } + void link(Node *x, Node *y) { + be_root(x); + x->fa = y; + } + void cut(Node *x, Node *y) { + be_root(x); + access(x); + splay(y); + y->fa = nil; + } + void modify_add(Node *x, Node *y, int w) { + be_root(x); + update_add(access(y), w); + } + void modify_set(Node *x, Node *y, int w) { + be_root(x); + update_set(access(y), w); + } + void query(Node *x, Node *y) { + be_root(x); + Node *r = access(y); + if(r->max[1] == NINF) puts("ALL SAME"); + else printf("%d %d\n", r->max[1], r->cnt[1]); + } + void work() { + scanf("%d", &T); + for(int t = 1; t <= T; ++t) { + scanf("%d%d", &n, &m); + init(); + for(int i = 1; i <= n; ++i) scanf("%d", &val[i]); + for(int i = 1, u, v; i < n; ++i) { + scanf("%d%d", &u, &v); + add_edge(u, v); + } + dfs(1, 0); + printf("Case #%d:\n", t); + for(int i = 0, x, y, a, b, op; i < m; ++i) { + scanf("%d", &op); + if(op == 1) { + scanf("%d%d%d%d", &x, &y, &a, &b); + cut(ptr[x], ptr[y]); + link(ptr[a], ptr[b]); + } else if(op == 2) { + scanf("%d%d%d", &a, &b, &x); + modify_set(ptr[a], ptr[b], x); + } else if(op == 3) { + scanf("%d%d%d", &a, &b, &x); + modify_add(ptr[a], ptr[b], x); + } else { + scanf("%d%d", &a, &b); + query(ptr[a], ptr[b]); + } + } + } + } +} S; +int main() { + S.work(); +} diff --git a/HDOJ/5003_autoAC.cpp b/HDOJ/5003_autoAC.cpp new file mode 100644 index 0000000..d6b339b --- /dev/null +++ b/HDOJ/5003_autoAC.cpp @@ -0,0 +1,40 @@ +#include +#include +#include +#include +using namespace std; +double POW(int n) +{ + double s = 1; + for(int i = 1; i <= n; i++) + { + s*=0.95; + } + return s; +} +int main() +{ + int n; + int t; + double a[57]; + while(~scanf("%d",&t)) + { + while(t--) + { + scanf("%d",&n); + for(int i = 1; i <= n; i++) + { + scanf("%lf",&a[i]); + } + sort(a+1,a+n+1); + double ans = 0; + int j = 0; + for(int i = n; i >= 1; i--) + { + ans+=a[i]*POW(j++); + } + printf("%.10lf\n",ans); + } + } + return 0; +} diff --git a/HDOJ/5004_autoAC.cpp b/HDOJ/5004_autoAC.cpp new file mode 100644 index 0000000..3423633 --- /dev/null +++ b/HDOJ/5004_autoAC.cpp @@ -0,0 +1,102 @@ +#include +#include +#include +using namespace std; +const int ROW = 16; +const int COL = 10; +const int dr[] = {-1, 0, 1, 0}; +const int dc[] = { 0, 1, 0,-1}; +struct Node { + int r,c; + Node() {} + Node(int _r,int _c) { + r = _r; + c = _c; + } +}; +int n; +bool ok; +char grid[ROW+1][COL+1]; +int ans[ROW*COL]; +bool full() { + for(int i = 1; i <= ROW; i++) { + for(int j = 1; j <= COL; j++) { + if(grid[i][j] != grid[1][1]) { + return false; + } + } + } + return true; +} +void dfs(int x,int y,int cur) { + char now[ROW+1][COL+1]; + int vis[ROW+1][COL+1]; + if(cur == n) { + if(full()) { + ok = true; + } + return ; + } + int color = grid[x][y] - '0'; + for(int i = 1; i <= 4; i++) { + if(color == i) { + continue; + } + memset(vis,0,sizeof(vis)); + memcpy(now,grid,sizeof(grid)); + queue que; + que.push(Node(x,y)); + vis[x][y] = true; + int r,c; + while(!que.empty()) { + Node front = que.front(); + que.pop(); + grid[front.r][front.c] = i + '0'; + for(int d = 0; d < 4; d++) { + r = front.r + dr[d]; + c = front.c + dc[d]; + if(grid[r][c] - '0' != color || vis[r][c]) { + continue; + } + vis[r][c] = true; + que.push(Node(r,c)); + } + } + ans[cur] = i; + dfs(x,y,cur+1); + if(ok) { + return ; + } + memcpy(grid,now,sizeof(grid)); + } +} +void solve() { + scanf("%d",&n); + memset(grid,0,sizeof(grid)); + for(int i = 1; i <= ROW; i++) { + scanf("%s",grid[i]+1); + } + for(int i = 1; i <= ROW; i++) { + for(int j = 1; j <= COL; j++) { + if(grid[i-1][j] == grid[i][j] || grid[i][j-1] == grid[i][j]) { + continue; + } + ok = false; + dfs(i,j,0); + if(ok) { + for(int k = 0; k < n; k++) + printf("%d %d %d\n",ans[k],i,j); + return; + } + } + } +} +int main() { + int t,cas = 1; + scanf("%d",&t); + while(t--) { + printf("Case #%d:\n",cas++); + solve(); + } + return 0; +} diff --git a/HDOJ/5005_autoAC.cpp b/HDOJ/5005_autoAC.cpp new file mode 100644 index 0000000..c0b7814 --- /dev/null +++ b/HDOJ/5005_autoAC.cpp @@ -0,0 +1,134 @@ +#include +#include +#include +#include +#include +#define maxn 210 +using namespace std; +struct node{ + int id,A,B; + node(){} + node(int x,int y,int z){ + id=x,A=y,B=z; + } +}; +vector e[maxn]; +vector vec; +int bel[maxn],A[maxn],B[maxn],dp[maxn][2],vis[maxn];; +bool cmp(const node &x,const node &y){ + return x.B>y.B; +} +void init(int n){ + for(int i=1;i<=n;i++) + e[i].clear(); +} +void dfs1(int now){ + if(dp[now][0]!=-1) + return; + if(bel[now]==-1){ + dp[now][0]=A[now]; + dp[now][1]=B[now]; + return; + } + for(int i=0;idp[now][0]){ + dp[now][0]=dp[v][0]; + dp[now][1]=dp[v][1]; + } + } + else{ + if(dp[v][1]>dp[now][1]){ + dp[now][0]=dp[v][0]; + dp[now][1]=dp[v][1]; + } + } + } +} +int dfs2(int now,int limit){ + if(vis[now]!=-1) + return vis[now]; + if(bel[now]==-1){ + if(A[now]>limit) + return vis[now]=0; + return vis[now]=1; + } + for(int i=0;i +#include +#include +#include +#include +#include +#include +#include +#include +#include +using namespace std; +#define rep(i,a,b) for(int i=(a);i<(int)(b);++i) +#define rrep(i,b,a) for(int i=(b);i>=(int)(a);--i) +#define eps 1e-8 +#define clr(a,x) memset(a,x,sizeof(a)) +#define LL long long +const int maxn = 10000+5; +int p[maxn]; +int find(int x) +{ + if (x == p[x]) return x; + return p[x] = find(p[x]); +} +int u[maxn*4],v[maxn*4],c[maxn*4]; +int id[maxn],tot; +double A[500][500]; +int N,M,S,T; +void input() +{ + scanf("%d%d%d%d",&N,&M,&S,&T); + rep(i,0,M) scanf("%d%d%d",u+i,v+i,c+i); +} +void gauss(int n) +{ + int i , j , k , r; + for(i=0; i < n; ++i) { + r = i; + for(j = i+1; j <= n; ++j) + if (fabs(A[j][i]) > fabs(A[r][i])) r = j; + if (r != i) for(j = 0; j <= n; ++j) swap(A[r][j],A[i][j]); + for(j = i+1; j <= n; ++j) A[i][j] /= A[i][i]; + A[i][i] = 1.0; + for(k = 0; k < n; ++k) { + if (fabs(A[k][i]) < eps || i == k) continue; + double f = A[k][i]; + for(j = 0; j <= n; ++j) A[k][j] -= f * A[i][j]; + } + } +} +void solve() +{ + rep(i,1,N+1) p[i] = i; + rep(i,0,M) if (c[i] == 0) + p[find(u[i])] = find(p[v[i]]); + if (find(S) == find(T)) { + printf("0.000000\n"); + return; + } + tot = 0; + rep(i,1,N+1) + if (find(i) == i) id[i] = tot++; + rep(i,1,N+1) + id[i] = id[find(i)]; + rep(i,0,tot) p[i] = i; + rep(i,0,M) p[find(u[i])] = find(v[i]); + if (find(S) != find(T)) { + puts("inf"); + return; + } + clr(A,0); + rep(i,0,M) { + if (id[u[i]] == id[v[i]]) continue; + int x = id[u[i]] , y = id[v[i]]; + ++A[x][x]; --A[x][y]; + ++A[y][y]; --A[y][x]; + } + S = id[S]; T = id[T]; + A[S][tot] = 1.0; A[T][tot] = -1.0; + A[tot-1][S]++; + gauss(tot); + printf("%.6lf\n",-A[T][tot] + A[S][tot] + eps); +} +int main() +{ + int T; cin >> T; + while (T--) { + input(); + solve(); + } +} diff --git a/HDOJ/5007_autoAC.cpp b/HDOJ/5007_autoAC.cpp new file mode 100644 index 0000000..f8ec9e8 --- /dev/null +++ b/HDOJ/5007_autoAC.cpp @@ -0,0 +1,35 @@ +#include +#include +char str[20000]; +int main() +{ + int i; + while(gets(str)) + { + int len=strlen(str); + for(i=0; i +#include +#include +#include +#define root 1,n,1 +#define lson l,mid,rt<<1 +#define rson mid+1,r,rt<<1|1 +#define M 120010 +#define INF 10000007 +using namespace std; +typedef long long LL; +LL ran[M],sa[M],X[M],Y[M],high[M],init[M]; +LL buc[M]; +struct SegmentTree{ + LL Min[M << 2]; + void pushup(LL rt){ + Min[rt] = min(Min[rt<<1],Min[rt<<1|1]); + } + void build(LL l,LL r,LL rt){ + if(l == r){ + Min[rt] = sa[l]; + return; + } + LL mid = (l + r) >> 1; + build(lson); + build(rson); + pushup(rt); + } + LL query(LL L,LL R,LL l,LL r,LL rt){ + if(L <= l && r <= R){ + return Min[rt]; + } + LL mid = (l + r) >> 1; + LL ans = INF; + if(L <= mid) ans = min(query(L,R,lson),ans); + if(mid + 1 <= R) ans = min(query(L,R,rson),ans); + return ans; + } +}; +SegmentTree sgt; +void calhigh(LL n) { + LL i , j , k = 0; + for(i = 1 ; i <= n ; i++) ran[sa[i]] = i; + for(i = 0 ; i < n ; high[ran[i++]] = k) + for(k?k--:0 , j = sa[ran[i]-1] ; init[i+k] == init[j+k] ; k++); +} +bool cmp(LL *r,LL a,LL b,LL l) { + return (r[a] == r[b] && r[a+l] == r[b+l]); +} +void suffix(LL n,LL m = 128) { + LL i , l , p , *x = X , *y = Y; + for(i = 0 ; i < m ; i ++) buc[i] = 0; + for(i = 0 ; i < n ; i ++) buc[ x[i] = init[i] ] ++; + for(i = 1 ; i < m ; i ++) buc[i] += buc[i-1]; + for(i = n - 1; i >= 0 ; i --) sa[ --buc[ x[i] ]] = i; + for(l = 1,p = 1 ; p < n ; m = p , l *= 2) { + p = 0; + for(i = n-l ; i < n ; i ++) y[p++] = i; + for(i = 0 ; i < n ; i ++) if(sa[i] >= l) y[p++] = sa[i] - l; + for(i = 0 ; i < m ; i ++) buc[i] = 0; + for(i = 0 ; i < n ; i ++) buc[ x[y[i]] ] ++; + for(i = 1 ; i < m ; i ++) buc[i] += buc[i-1]; + for(i = n - 1; i >= 0 ; i --) sa[ --buc[ x[y[i]] ] ] = y[i]; + for(swap(x,y) , x[sa[0]] = 0 , i = 1 , p = 1 ; i < n ; i ++) + x[ sa[i] ] = cmp(y,sa[i-1],sa[i],l) ? p-1 : p++; + } + calhigh(n-1); +} +LL Log[M]; +LL best[20][M]; +void initRMQ(LL n) { + for(LL i = 1; i <= n ; i ++) best[0][i] = high[i]; + for(LL i = 1; i <= Log[n] ; i ++) { + LL limit = n - (1<>1)]); + } + } +} +LL lcp(LL a,LL b) { + if(a>b)return 0; + LL t = Log[b - a + 1]; + return min(best[t][a] , best[t][b - (1<dlen[n]||k<=0){ + start=len=0; + return ; + } + LL l=1,r=n; + while(l<=r){ + LL mid=(l+r)>>1; + if(dlen[mid]>=k) r=mid-1; + else l=mid+1; + } + start=l; + len=k-dlen[start-1]+high[start]; +} +LL findLcp(LL start,LL len,LL n){ + LL l=start + 1,r=n; + while(l<=r){ + LL mid=(l+r)>>1; + if(lcp(start+1,mid)>=len)l=mid+1; + else r=mid-1; + } + return sgt.query(start,r,root); +} +int main() { + LL l,r,q; + LL v,u; + LL start,llen; + Log[0] = -1; + for(LL i = 1; i < M ; i ++) { + Log[i] = (i&(i-1)) ? Log[i-1] : Log[i-1] + 1 ; + } + while(scanf("%s",str)!=EOF){ + l = r = 0; + LL n=strlen(str); + for(LL i=0;i +#include +#include +#include +#include +using namespace std ; +const int INF=0xfffffff ; +int n,dp[50005] ; +struct node +{ + int num ; + int id,rank ; +}kk[50005] ; +int a[50005] ; +int vis[50005] ; +int cmp1(node aa,node bb) +{ + return aa.num v ; + for(int i=0 ;i=dp[m])break ; + dp[j]=min(dp[j],dp[i]+cnt*cnt) ; + } + for(int j=0 ;j +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#define REP(i,n) for(int i=0;i=b;--i) +#define MP make_pair +#define LL long long +#define ULL unsigned long long +#define X first +#define Y second +#define MAXN 1000050 +using namespace std; +map mp; +int dx[] = { 0, 0, 1, -1 }; +int dy[] = { 1, -1, 0, 0 }; +char s[6][9]; +int id[6][9]; +int qx[100]; +int qy[100]; +int qcnt; +ULL q[MAXN]; +ULL bas[100]; +struct node { + char a[6][9]; + int scnt; + node() { + } + ; + node(ULL now) { + scnt = 0; + REP(i,6) + REP(j,8) + a[i][j] = s[i][j]; + REP(i,qcnt) + { + ULL k = now & 3; + now >>= 2; + if (k == 0) + continue; + if (k == 1) { + a[qx[i]][qy[i]] = 'S'; + scnt++; + } + if (k == 2) + a[qx[i]][qy[i]] = 'M'; + if (k == 3) + a[qx[i]][qy[i]] = 'P'; + } + } +}; +void init() { + qcnt = 0; + int cid = 0; + memset(id, -1, sizeof(id)); + REP(i,6) + REP(j,8) + { + if (s[i][j] == '#' || s[i][j] == 'N') + continue; + qx[qcnt] = i; + qy[qcnt++] = j; + id[i][j] = cid++; + } +} +ULL geths(char s[6][9]) { + ULL ans = 0; + REP(i,6) + REP(j,8) + { + if (s[i][j] == 'S') { + ans += bas[id[i][j] << 1]; + continue; + } + if (s[i][j] == 'M') { + ans += 2 * bas[id[i][j] << 1]; + continue; + } + if (s[i][j] == 'P') { + ans += 3 * bas[id[i][j] << 1]; + } + } + return ans; +} +bool check(int x, int y) { + if (x < 0 || x >= 6 || y < 0 || y >= 8) + return false; + return true; +} +node move(node a, int x, int y, int dxx, int dyy, int &p) { + char c = a.a[x][y]; + while (true) { + int xx = x + dxx; + int yy = y + dyy; + if ((!check(xx, yy)) || a.a[xx][yy] != '.') { + p = 1; + return a; + } + a.a[xx][yy] = a.a[x][y]; + a.a[x][y] = '.'; + if (c == 'P') { + int flag=0; + for (int j = 0; j < 4; ++j) { + int px = xx + dx[j]; + int py = yy + dy[j]; + if (!check(px, py)) + continue; + if (a.a[px][py] == 'N') { + p = 0; + return a; + } + if (a.a[px][py] == 'S' || a.a[px][py] == 'M') { + if (a.a[px][py] == 'S') { + a.scnt--; + if (a.scnt == 0) { + p = 0; + return a; + } + } + a.a[px][py] = '.'; + flag=1; + } + } + if(flag) + { + p=1; + return a; + } + } else { + for (int i = 0; i < 4; ++i) { + int px = xx + dx[i]; + int py = yy + dy[i]; + if (!check(px, py)) + continue; + if (a.a[px][py] == 'P') { + if (c == 'S') { + a.scnt--; + if (a.scnt == 0) { + p = 0; + return a; + } + } + a.a[xx][yy] = '.'; + p = 1; + return a; + } + } + for (int i = 0; i < 4; ++i) { + int px = xx + dx[i]; + int py = yy + dy[i]; + if (!check(px, py)) + continue; + if (a.a[px][py] == 'N') { + if (c == 'S') { + p = 2; + return a; + } + p = 0; + return a; + } + } + } + x = xx; + y = yy; + } + return a; +} +int d[MAXN]; +int bfs(ULL st) { + int tail = 0; + d[0] = 0; + q[tail++] = st; + mp.clear(); + mp[st] = 1; + for (int i = 0; i < tail; ++i) { + node a = node(q[i]); + REP(j,6) + REP(k,8) + { + if (a.a[j][k] == 'S' || a.a[j][k] == 'M' || a.a[j][k] == 'P') { + for (int x = 0; x < 4; ++x) { + int p; + node e = move(a, j, k, dx[x], dy[x], p); + if (p == 2) { + return d[i] + 1; + } + if (p == 1) { + ULL hs = geths(e.a); + if (mp.find(hs) == mp.end()) { + mp[hs] = 1; + q[tail] = hs; + d[tail++] = d[i] + 1; + } + } + } + } + } + } + printf("tail:%d\n",tail); + return -1; +} +int main() { + bas[0] = 1; + for (int i = 1; i <= 64; ++i) + bas[i] = bas[i - 1] * 2; + while(scanf(" %s",s[0])!=EOF){ + for(int i=1;i<6;++i)scanf(" %s",s[i]); + init(); + ULL hs=geths(s); + REP(i,6)REP(j,8)if(s[i][j]=='S'||s[i][j]=='M'||s[i][j]=='P')s[i][j]='.'; + int ans=bfs(hs); + printf("%d\n",ans); + } + return 0; +} diff --git a/HDOJ/5011_autoAC.cpp b/HDOJ/5011_autoAC.cpp new file mode 100644 index 0000000..4fb4c94 --- /dev/null +++ b/HDOJ/5011_autoAC.cpp @@ -0,0 +1,29 @@ +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +const int inf=0xfffffff; +typedef long long ll; +using namespace std; +int main() +{ + int n; + ll a, s; + while(~scanf("%d", &n)){ + scanf("%I64d", &s); + for(int i=1; i +#include +#include +#include +using namespace std; +struct node +{ + int s1,s2,s3,s4,s5,s6; + int sum; +} q[800000]; +int a[7],b[7]; +int c[7][7][7][7][7][7]; +void bfs() +{ + memset(c,0,sizeof(c)); + struct node t,r; + t.s1=b[1]; + t.s2=b[2]; + t.s3=b[3]; + t.s4=b[4]; + t.s5=b[5]; + t.s6=b[6]; + t.sum=0; + int k=0,l=0; + q[l++]=t; + while(k +#include +#include +#include +#include +#include +#include +#include +#include +using namespace std; +#define RD(x) scanf("%d",&x) +#define RD2(x,y) scanf("%d%d",&x,&y) +#define RD3(x,y,z) scanf("%d%d%d",&x,&y,&z) +#define clr0(x) memset(x,0,sizeof(x)) +typedef long long LL; +const int maxn = 20; +int n, m; +double p[maxn][maxn],h[maxn][maxn],f[maxn][maxn][maxn],g[maxn][maxn][maxn]; +int main() { + while (~RD2(m,n)) { + for (int i = 1; i <= m; i++) { + scanf("%lf", &p[i][1]); + p[i][0] = 1.0; + for (int j = 2; j <= n; j++) { + p[i][j] = p[i][j - 1] * p[i][1]; + } + } + for (int i = 1; i <= m; i++) { + for (int j = 1; j <= n; j++) { + scanf("%lf", &h[i][j]); + } + } + clr0(f),clr0(g); + double ans = 0; + for (int i = 2; i <= n; i++) { + f[i][0][0] = 1; + for (int j = 1; j <= m; j++) { + for (int x = m; x >= 0; x--) { + for (int y = x; y >= 0; y--) { + f[i][x][y] *= (1.0 - p[j][i - 2]); + if (x > 0) { + f[i][x][y] += f[i][x - 1][y] * p[j][i - 2] * (1.0 - p[j][1]); + if (y > 0) { + f[i][x][y] += f[i][x - 1][y - 1] * p[j][i - 1]; + } + } + g[i][x][y] *= (1.0 - p[j][i - 2]); + if (x > 0) { + g[i][x][y] += g[i][x - 1][y] * p[j][i - 2] * (1.0 - p[j][1]); + if (y > 0) { + g[i][x][y] += (g[i][x - 1][y - 1] + f[i][x - 1][y - 1] * h[j][i]) * p[j][i - 1]; + } + } + } + } + } + for (int x = 1; x <= m; x++) { + for (int y = 1; y <= x; y++) { + ans += g[i][x][y] * ((double)y / x + 1.0); + } + } + } + for (int i = 1; i <= m; i++) { + ans += h[i][1]; + } + printf("%.10f\n", ans); + } + return 0; +} diff --git a/HDOJ/5014_autoAC.cpp b/HDOJ/5014_autoAC.cpp new file mode 100644 index 0000000..21b51b6 --- /dev/null +++ b/HDOJ/5014_autoAC.cpp @@ -0,0 +1,47 @@ +#include +#include +#include +#include +#include +#include +#include +using namespace std; +#define ll __int64 +#define up(i,x,y) for(i=x;i<=y;i++) +#define up2(i,x,y) for(i=x;y;i++) +#define down(i,x,y) for(i=x;i>=y;i--) +#define down2(i,x,y) for(i=x;y;i--) +#define mem(a,b) memset(a,b,sizeof(a)) +#define s(a) scanf("%d",&a) +#define s64(a) scanf("%I64d",&a) +#define w(a) while(a) +int n,a[100005],i,has[100005]; +int main() +{ + w(~s(n)) + { + up(i,0,n) + s(a[i]); + printf("%I64d\n",(ll)n*n+n); + mem(has,-1); + down(i,n,0) + { + if(has[i]>=0) continue; + int num=0,s=1,t=i; + w(t) + { + int tem=((t&1)^1); + num=num+s*tem; + s*=2; + t=t/2; + } + has[num]=i; + has[i]=num; + } + printf("%d",has[a[0]]); + up(i,1,n) + printf(" %d",has[a[i]]); + printf("\n"); + } + return 0; +} diff --git a/HDOJ/5015_autoAC.cpp b/HDOJ/5015_autoAC.cpp new file mode 100644 index 0000000..6c1991b --- /dev/null +++ b/HDOJ/5015_autoAC.cpp @@ -0,0 +1,89 @@ +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#pragma comment(linker, "/STACK:1024000000,1024000000") +using namespace std; +#define maxn 110000 +#define mod 10000007 +#define LL __int64 +struct matrix +{ + LL mat[15][15]; + matrix() + { + memset(mat,0,sizeof(mat)); + } +}; +int a[11]; +int n; +matrix mul(matrix A,matrix B) +{ + matrix C; + int i,j,k; + for(i=1; i<=n+2; i++) + { + for(j=1; j<=n+2; j++) + { + for(k=1; k<=n+2; k++) + { + C.mat[i][j]=(C.mat[i][j]+A.mat[i][k]*B.mat[k][j])%mod; + } + } + } + return C; +} +matrix powmul(matrix A,int k) +{ + matrix B; + for(int i=1;i<=n+2;i++)B.mat[i][i]=1; + while(k>=1) + { + if(k&1)B=mul(B,A); + A=mul(A,A); + k=k/2; + } + return B; +} +void print(matrix A) +{ + cout<<"matrix A"< +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +using namespace std; +const int MAXN = 100010; +const int INF = 0x3f3f3f3f; +struct Edge{ + int to,next,w; +}edge[MAXN*2]; +int head[MAXN],tot; +void init(){ + tot = 0; + memset(head,-1,sizeof(head)); +} +inline void addedge(int u,int v,int w){ + edge[tot].to = v; + edge[tot].w = w; + edge[tot].next = head[u]; + head[u] = tot++; +} +int size[MAXN],vis[MAXN],fa[MAXN],que[MAXN]; +int TT; +inline int getroot(int u){ + int Min = MAXN, root = 0; + int l,r; + que[l = r = 1] = u; + fa[u] = 0; + for(;l <= r;l++) + for(int i = head[que[l]]; i != -1;i = edge[i].next){ + int v = edge[i].to; + if(v == fa[que[l]] || vis[v] == TT)continue; + que[++r] = v; + fa[v] = que[l]; + } + for(l--;l;l--){ + int x = que[l], Max = 0; + size[x] = 1; + for(int i = head[x];i != -1;i = edge[i].next){ + int v = edge[i].to; + if(v == fa[x] || vis[v] == TT)continue; + Max = max(Max,size[v]); + size[x] += size[v]; + } + Max = max(Max,r - size[x]); + if(Max < Min){ + Min = Max; root = x; + } + } + return root; +} +int ans[MAXN]; +pairpp[MAXN]; +pairnp[MAXN]; +int dis[MAXN]; +int type[MAXN]; +inline void go(int u,int pre,int w,int tt){ + int l,r; + que[l = r = 1] = u; + fa[u] = pre; dis[u] = w; + for(;l <= r;l++) + for(int i = head[que[l]];i != -1;i = edge[i].next){ + int v = edge[i].to; + if(v == fa[que[l]] || vis[v] == TT)continue; + que[++r] = v; + fa[v] = que[l]; + dis[v] = dis[que[l]] + edge[i].w; + } + int cnt = 0; + for(int i = 1;i <= r;i++){ + int x = que[i]; + pp[cnt++] = make_pair(np[x].first-dis[x],np[x].second); + } + sort(pp,pp+cnt); + for(int i = 1;i <= r;i++){ + int x = que[i]; + if(type[x])continue; + int id = lower_bound(pp,pp+cnt,make_pair(dis[x],x)) - pp; + ans[x] += (cnt-id)*tt; + } +} +void solve(int u){ + int root = getroot(u); + vis[root] = TT; + go(root,0,0,1); + for(int i = head[root];i != -1;i = edge[i].next){ + int v = edge[i].to; + if(vis[v] == TT)continue; + go(v,root,edge[i].w,-1); + } + for(int i = head[root];i != -1;i = edge[i].next){ + int v = edge[i].to; + if(vis[v] == TT)continue; + solve(v); + } +} +bool ff[MAXN]; +int main() +{ + int n; + memset(vis,0,sizeof(vis)); + TT = 0; + while(scanf("%d",&n) == 1){ + init(); + int u,v,w; + for(int i = 1;i < n;i++){ + scanf("%d%d%d",&u,&v,&w); + addedge(u,v,w); + addedge(v,u,w); + } + for(int i = 1;i <= n;i++)scanf("%d",&type[i]); + queueq; + for(int i = 1;i <= n;i++){ + if(type[i]){ + np[i] = make_pair(0,i); + ff[i] = true; + q.push(i); + } + else{ + np[i] = make_pair(INF,0); + ff[i] = false; + } + } + while(!q.empty()){ + u = q.front(); + q.pop(); + ff[u] = false; + for(int i = head[u];i != -1;i = edge[i].next){ + v = edge[i].to; + pairtmp = make_pair(np[u].first+edge[i].w,np[u].second); + if(tmp < np[v]){ + np[v] = tmp; + if(!ff[v]){ + ff[v] = true; + q.push(v); + } + } + } + } + TT++; + for(int i = 1;i <= n;i++)ans[i] = 0; + solve(1); + int ret = 0; + for(int i = 1;i <= n;i++)ret = max(ret,ans[i]); + printf("%d\n",ret); + } + return 0; +} diff --git a/HDOJ/5017_autoAC.cpp b/HDOJ/5017_autoAC.cpp new file mode 100644 index 0000000..898c709 --- /dev/null +++ b/HDOJ/5017_autoAC.cpp @@ -0,0 +1,57 @@ +#include +#include +#include +#include +#define Mod 1000000007 +#define eps 1e-8 +using namespace std; +int dx[8] = {0,0,1,-1,1,-1,1,-1}; +int dy[8] = {1,-1,0,0,1,1,-1,-1}; +double a,b,c,d,e,f; +double dis(double x,double y,double z) +{ + return sqrt(x*x + y*y + z*z); +} +double calc(double x,double y) +{ + double A = c; + double B = d*y+e*x; + double C = f*x*y + a*x*x + b*y*y - 1.0; + double delta = B*B-4.0*A*C; + if(delta < 0.0) return Mod+10.0; + delta = sqrt(delta); + double soz1 = (-B + delta)/(2.0*A); + double soz2 = (-B - delta)/(2.0*A); + if(dis(x,y,soz1) < dis(x,y,soz2)) + return soz1; + return soz2; +} +double Simulated_Annealing() +{ + double x = 0,y = 0,z = sqrt(1.0/c); + double step = 1.0, rate = 0.99; + while(step > eps) + { + for(int k=0;k<8;k++) + { + double kx = x + step*dx[k]; + double ky = y + step*dy[k]; + double kz = calc(kx,ky); + if(kz >= Mod) continue; + if(dis(kx,ky,kz) < dis(x,y,z)) + { + x = kx,y = ky,z = kz; + } + } + step *= rate; + } + return dis(x,y,z); +} +int main() +{ + while(scanf("%lf%lf%lf%lf%lf%lf",&a,&b,&c,&d,&e,&f)!=EOF) + { + printf("%.7f\n",Simulated_Annealing()); + } + return 0; +} diff --git a/HDOJ/5018_autoAC.cpp b/HDOJ/5018_autoAC.cpp new file mode 100644 index 0000000..af2c6e1 --- /dev/null +++ b/HDOJ/5018_autoAC.cpp @@ -0,0 +1,41 @@ +#include +#include +#include +#include +#include +using namespace std; +int main() +{ + int F[1000]; + int A,B,C,T,i; + scanf("%d",&T); + while(T--) + { + scanf("%d%d%d",&A,&B,&C); + F[0]=A,F[1]=B; + int flag=0; + for(i=2;;i++) + { + F[i]=F[i-1]+F[i-2]; + if(F[i]==C) + { + flag=1; + break; + } + if(F[i]>C) + { + break; + } + } + if(F[0]==C||F[1]==C) flag=1; + if(flag==1) + { + printf("Yes\n"); + } + else + { + printf("No\n"); + } + } + return 0; +} diff --git a/HDOJ/5019_autoAC.cpp b/HDOJ/5019_autoAC.cpp new file mode 100644 index 0000000..929230d --- /dev/null +++ b/HDOJ/5019_autoAC.cpp @@ -0,0 +1,42 @@ +#include +#include +#include +#include +#include +using namespace std; +typedef __int64 LL; +LL gcd(LL a, LL b) +{ + if(b==0) + return a; + return gcd(b, a%b); +} +int main() +{ + LL a, b, c; + int T; + vector v; + scanf("%d", &T); + while(T--) + { + scanf("%I64d%I64d%I64d", &a, &b, &c); + LL temp = gcd(a, b); + v.clear(); + int cnt = 0; + for(LL i=1; i*i<=temp; ++i) + { + if(temp%i==0) + { + v.push_back(i); + if(i*i!=temp) + v.push_back(temp/i); + } + } + sort(v.begin(), v.end()); + if(v.size() >= c) + printf("%I64d\n", v[v.size()-c]); + else + printf("-1\n"); + } + return 0; +} diff --git a/HDOJ/5020_autoAC.cpp b/HDOJ/5020_autoAC.cpp new file mode 100644 index 0000000..9340475 --- /dev/null +++ b/HDOJ/5020_autoAC.cpp @@ -0,0 +1,55 @@ +#include +#include +#include +#include +#include +#include +#include +#include +#include +using namespace std; +#define INF 1e9 +#define maxn 1010 +#define rep(i,x,y) for(int i=x;i<=y;i++) +#define mset(x) memset(x,0,sizeof(x)) +typedef pair pii; +int t, n; +struct point{ + int x, y; +}p[maxn]; +map< pii, int > tb; +map< pii, int >::iterator it; +bool cmp(const point& a, const point& b){ + return (a.x==b.x&&a.y>t; + while(t--){ + cin>>n; + rep(i,1,n) scanf("%d%d", &p[i].x, &p[i].y); + sort(p+1, p+n+1, cmp); + int cnt=0; + rep(i,1,n-2){ + tb.clear(); + rep(j,i+1,n){ + int dx = p[j].x - p[i].x; + int dy = p[j].y - p[i].y; + int d = gcd(dx, dy); + dx = dx/d; + dy = dy/d; + tb[make_pair(dx,dy)]++; + } + for(it=tb.begin(); it!=tb.end(); it++){ + int x = it->second; + if(x>=2) + cnt += x*(x-1)/2; //C(x,2) + } + } + cout< +#include +#include +using namespace std ; +typedef long long LL ; +#define travel( e , H , u ) for ( Edge* e = H[u] ; e ; e = e -> next ) +#define rep( i , a , b ) for ( int i = ( a ) ; i < ( b ) ; ++ i ) +#define rev( i , a , b ) for ( int i = ( a ) ; i >= ( b ) ; -- i ) +#define FOR( i , a , b ) for ( int i = ( a ) ; i <= ( b ) ; ++ i ) +#define clr( a , x ) memset ( a , x , sizeof a ) +#define cpy( a , x ) memcpy ( a , x , sizeof a ) +const int MAXN = 100005 ; +struct Node { + int x , idx ; + double v ; + bool operator < ( const Node& a ) const { + return x < a.x ; + } +} p[MAXN] ; +int idx[MAXN] ; +int n , m ; +double T[MAXN] ; +void add ( int x , double v ) { + while ( x <= n ) { + T[x] += v ; + x += x & -x ; + } +} +double sum ( int x , double ans = 0 ) { + while ( x ) { + ans += T[x] ; + x -= x & -x ; + } + return ans ; +} +int L_find ( int x ) { + int l = 1 , r = n ; + while ( l < r ) { + int m = ( l + r ) >> 1 ; + if ( p[m].x >= x ) r = m ; + else l = m + 1 ; + } + return l ; +} +int R_find ( int x ) { + int l = 1 , r = n ; + while ( l < r ) { + int m = ( l + r + 1 ) >> 1 ; + if ( p[m].x <= x ) l = m ; + else r = m - 1 ; + } + return r ; +} +void solve () { + int x , k ; + double ans = 0 ; + clr ( T , 0 ) ; + scanf ( "%d%d" , &n , &m ) ; + FOR ( i , 1 , n ) { + scanf ( "%d%lf" , &p[i].x , &p[i].v ) ; + p[i].idx = i ; + } + sort ( p + 1 , p + n + 1 ) ; + FOR ( i , 1 , n ) add ( i , p[i].v ) ; + FOR ( i , 1 , n ) idx[p[i].idx] = i ; + while ( m -- ) { + scanf ( "%d%d" , &x , &k ) ; + int l = 1 , r = p[n].x ; + int v = idx[x] ; + while ( l <= r ) { + int mid = ( l + r ) >> 1 ; + int L = L_find ( p[v].x - mid ) ; + int R = R_find ( p[v].x + mid ) ; + if ( R - L < k ) l = mid + 1 ; + else if ( R - L > k + 1 ) r = mid - 1 ; + else if ( R - L == k ) { + double tmp = ( sum ( R ) - sum ( L - 1 ) - p[v].v ) / k ; + ans += tmp ; + add ( v , -p[v].v ) ; + add ( v , tmp ) ; + p[v].v = tmp ; + break ; + } else if ( R - L == k + 1 ) { + if ( p[v].x - p[L].x == p[R].x - p[v].x ) { + if ( p[L].idx < p[R].idx ) -- R ; + else ++ L ; + } + else if ( p[v].x - p[L].x < p[R].x - p[v].x ) -- R ; + else ++ L ; + double tmp = ( sum ( R ) - sum ( L - 1 ) - p[v].v ) / k ; + ans += tmp ; + add ( v , -p[v].v ) ; + add ( v , tmp ) ; + p[v].v = tmp ; + break ; + } + } + } + printf ( "%.3f\n" , ans ) ; +} +int main () { + int T ; + scanf ( "%d" , &T ) ; + while ( T -- ) solve () ; + return 0 ; +} diff --git a/HDOJ/5022_autoAC.cpp b/HDOJ/5022_autoAC.cpp new file mode 100644 index 0000000..cc51cb1 --- /dev/null +++ b/HDOJ/5022_autoAC.cpp @@ -0,0 +1,125 @@ +#include +#include +#include +#include +using namespace std; +typedef long long int64; +int64 v[210000],tx[210000],ty[210000],rk[210000],a,b,c,d,s,t,P,pp,x,y,sp,gg,tot,rs,ans,cnt; +int64 gcd(int64 a,int64 b) +{ + x=1,y=0; + if(!b) return a; + int64 d=gcd(b,a%b); + int64 xx=x; x=y; y=xx-a/b*y; + return d; +} +int64 qpow(int64 a,int64 b,int64 c) +{ + int64 res=1; + for(;b;b>>=1,a=a*a%c) + if(b&1) res=res*a%c; + return res; +} +int64 dt2(int64 a) +{ + int l=1,r=cnt,mid; + while(l+1>1; + if(tx[rk[mid]]>1; + if(v[mid]=a) return v[l]; + return v[r]; +} +int64 solve(int64 a,int64 b,int64 P,int64 t) +{ + a=(a+P)%P; b=(b+P)%P; tot=0; int64 sp=0,ans=b; + for(;(sp+1)*(sp+1)<=t;++sp); + for(int i=0;sp*sp+i<=t;++i) + ans=min(ans,(a*(sp*sp+i)+b)%P); + if(!sp) return ans; + for(int i=1;i<=sp;++i) v[++tot]=(a*sp*i+b)%P; + sort(v+1,v+tot+1); + for(int i=0;i<=sp;++i) + { + int64 x=a*i%P; + ans=min(ans,(v[1]+P-x)%P); + ans=min(ans,(t2(x)-x+P)%P); + } + return ans; +} +bool cmp(int a,int b) +{ + return tx[a]1) v[++tot]=pp; pp=P-1; + gg=getpg(P); cnt=0; + for(int i=1;i<=sp;++i) tx[++cnt]=qpow(gg,sp*i,P),ty[cnt]=sp*i,rk[cnt]=cnt; + sort(rk+1,rk+cnt+1,cmp); + a=dlog(a); b=dlog(b); c=dlog(c); + a=(pp-a)%pp; c=(c-b*s%pp+pp)%pp; t-=s; + d=gcd(pp,gcd(a,b)); + if(c%d) + { + printf("impossible\n"); continue; + } + a/=d; b/=d; c/=d; pp/=d; d=gcd(pp,a); + gcd(b,d); x=(x%d+d)%d; rs=c*x%d; + if(t +#include +#include +#include +using namespace std; +#define lson l, mid, root<<1 +#define rson mid+1, r, root<<1|1 +const int N = 1e6 + 5; +set s; +set ::iterator it; +struct Node { + int color; + int left; + int right; + int mid; +} a[N<<2]; +void Push_Down(int root) { + if(a[root].color) { + a[root<<1].color = a[root].color; + a[root<<1|1].color = a[root].color; + a[root].color = 0; + } +} +void Build_Tree(int l, int r, int root) { + int mid = (l + r) >> 1; + a[root].left = l; + a[root].right = r; + a[root].mid = mid; + a[root].color = 2; + if(l == r) return; + Build_Tree(lson); + Build_Tree(rson); +} +void Update(int l, int r, int c, int root) { + if(a[root].left == l && a[root].right == r) { + a[root].color = c; + return; + } + if(a[root].color == c) return; + Push_Down(root); + if(l > a[root].mid) Update(l, r, c, root<<1|1); + else if(r <= a[root].mid) Update(l, r, c, root<<1); + else { + Update(l, a[root].mid, c, root<<1); + Update(a[root].mid+1, r, c, root<<1|1); + } +} +void Query(int l, int r, int root) { + if(a[root].color) { + s.insert(a[root].color); + return ; + } + if(l > a[root].mid) Query(l, r, root<<1|1); + else if(r <= a[root].mid) Query(l, r, root<<1); + else { + Query(l, a[root].mid, root<<1); + Query(a[root].mid+1, r, root<<1|1); + } +} +int main() { + int n, m; + int l, r, c; + char op[10]; + while(~scanf("%d%d", &n, &m) && (n + m)) { + Build_Tree(1, n, 1); + for(int i = 0; i < m; i++) { + scanf("%s%d%d", op, &l, &r); + if(op[0] == 'P') { + scanf("%d", &c); + Update(l, r, c, 1); + } + else { + s.clear(); + Query(l, r, 1); + int ss = s.size(); + for(it = s.begin(); it != s.end(); it++) { + printf("%d", *it); + if(ss > 1) printf(" "); + ss--; + } + printf("\n"); + } + } + } + return 0; +} diff --git a/HDOJ/5024_autoAC.cpp b/HDOJ/5024_autoAC.cpp new file mode 100644 index 0000000..64ea434 --- /dev/null +++ b/HDOJ/5024_autoAC.cpp @@ -0,0 +1,65 @@ +#include +#include +#include +#include +using namespace std; +#define N 102 +char mat[N][N]; +int maxn,n; +int dir1[4][2] = {{1,0},{-1,0},{0,1},{0,-1}}; +int dir2[4][2] = {{1,1},{-1,1},{1,-1},{-1,-1}}; +void solve1(int x,int y) +{ + int tmp[4]; + for(int i=0;i<4;i++){ + int xx=x,yy=y; + tmp[i]=0; + while(true){ + xx+=dir1[i][0]; + yy+=dir1[i][1]; + if(mat[xx][yy]!='#'&&xx>=0&&xx=0&&yy=0&&xx=0&&yy>mat[i][j]; + for(int i=0;i +#include +#include +#include +#include +#include +using namespace std ; +int n,m ; +int sx,sy ; +int tx,ty ; +char mp[105][105] ; +int vis[105][105][10][33] ; +struct node +{ + int x,y ; + int time ; + int snake ; + int key ; + friend bool operator <(node a,node b) + { + return a.time>b.time ; + } +} ; +int cnt ; +struct sk +{ + int x,y ; +}ss[10] ; +int OK(node a) +{ + if(a.x==tx && a.y==ty) + { + if(a.key==m)return 1 ; + } + return 0 ; +} +int dx[]={1,-1,0,0} ; +int dy[]={0,0,1,-1} ; +int bfs(int x,int y) +{ + priority_queue q ; + node s ; + s.x=x ;s.y=y ;s.time=0 ;s.snake=0 ;s.key=0 ; + vis[x][y][0][0]=1 ; + q.push(s) ; + while(!q.empty()) + { + node u=q.top() ; + if(OK(u))return u.time ; + q.pop() ; + for(int i=0 ;i<4 ;i++) + { + int xx=u.x+dx[i] ; + int yy=u.y+dy[i] ; + if(xx<0 || xx>=n || yy<0 || yy>=n)continue ; + if(mp[xx][yy]=='#')continue ; + if(vis[xx][yy][u.key][u.snake])continue ; + node T ; + T=u ; + T.x=xx ;T.y=yy ;T.time=u.time+1 ; + if(mp[xx][yy]>='1' && mp[xx][yy]<='9') + { + int num=mp[xx][yy]-'0'-1 ; + if(T.key==num) + { + T.key++ ; + vis[xx][yy][T.key][T.snake]=1 ; + q.push(T) ; + } + else + { + vis[xx][yy][T.key][T.snake]=1 ; + q.push(T) ; + } + } + else if(mp[xx][yy]=='S') + { + for(int i=0 ;i>i)&1) + { + vis[xx][yy][T.key][T.snake]=1 ; + q.push(T) ; + } + else + { + T.time++ ; + T.snake+=(1< +#include +#include +#include +#include +#include +#include +using namespace std; +const double eps=1.0e-8; +typedef complex point; +typedef vector polygon; +struct line : public vector { + line() {} + line(const point& a, const point& b) { push_back(a); push_back(b); } +}; +inline point vec(const line& l) { return l[1]-l[0];} +inline double dot (const point& a, const point& b) { return (a*conj(b)).real();} +inline double cross(const point& a, const point& b) { return (conj(a)*b).imag();} +inline int dlcmp(const double& x){ + return x<-eps?-1:x>eps; +} +bool intersectSP(const line& s, const point& p) { + return abs(s[0]-p)+abs(s[1]-p)>T; + while(T--){ + double Ts, Vr, Vs; cin>>Ts>>Vr>>Vs; + double Xo, Yo, Xp, Yp; cin>>Xo>>Yo>>Xp>>Yp; + point O(Xo,Yo), P(Xp,Yp); + cin>>n; + p.clear(); + double x, y; + for(int i=0; i=0; + sum+=abs(p[i]-p[(i+1)%n]); + } + int cnt=0; + for(int i=0; i +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +using namespace std; +#define MP(x,y) make_pair((x),(y)) +#define PB(x) push_back(x) +const int INF = 1000111222; +const double INFF = 1e100; +const double eps = 1e-8; +const int mod = 1000000007; +const int NN = 100010; +const int MM = 400010; +vectorad[NN]; +vectordel[NN]; +struct TR +{ + int l,r,col,ci; + int mid() + { + return (l+r)>>1; + } +}tr[NN*4]; +struct G +{ + int v,next; +}E[NN*2]; +int p[NN],T; +//c_dfs1 +int deep[NN],si[NN],per[NN],anc[NN]; +//c_dfs2 +int tsp,pos[NN],top[NN]; +int ans[NN],dui[NN]; +void add(int u,int v) +{ + E[T].v=v; + E[T].next=p[u]; + p[u]=T++; +} +void c_dfs1(int u,int fa,int cen) +{ + anc[u]=fa; + deep[u]=cen; + si[u]=1; + per[u]=-1; + int i,v; + for(i=p[u];i+1;i=E[i].next) + { + v=E[i].v; + if(v==fa)continue; + c_dfs1(v,u,cen+1); + si[u]+=si[v]; + if(per[u]==-1 || si[v]>si[ per[u] ]) + per[u]=v; + } +} +void c_dfs2(int u,int fa,int now_top) +{ + pos[u]=++tsp; + top[u]=now_top; + if(per[u]!=-1)c_dfs2(per[u],u,now_top); + int i,v; + for(i=p[u];i+1;i=E[i].next) + { + v=E[i].v; + if(v==per[u] || v==fa)continue; + c_dfs2(v,u,v); + } +} +void c_update(int u,int v,int col) +{ + while(top[u]!=top[v]) + { + if(deep[ top[u] ] > deep[ top[v] ]) + swap(u,v); + ad[ pos[ top[v] ] ].PB(col); + del[ pos[v] ].PB(col); + v=anc[ top[v] ]; + } + if(pos[u]>pos[v]) + swap(u,v); + ad[ pos[u] ].PB(col); + del[ pos[v] ].PB(col); +} +void push_up(int R) +{ + if(tr[R<<1].ci >= tr[R<<1|1].ci) + { + tr[R].col = tr[R<<1].col; + tr[R].ci = tr[R<<1].ci; + } + else + { + tr[R].col = tr[R<<1|1].col; + tr[R].ci = tr[R<<1|1].ci; + } +} +void build(int l,int r,int R) +{ + tr[R].l = l; + tr[R].r = r; + if(l==r) + { + tr[R].col = l; + tr[R].ci = 0; + return; + } + int mid = tr[R].mid(); + build(l,mid,R<<1); + build(mid+1,r,R<<1|1); + push_up(R); +} +void update(int x,int R,int ad) +{ + if(tr[R].l == tr[R].r) + { + tr[R].ci += ad; + return; + } + int mid = tr[R].mid(); + if(x <= mid) + update(x,R<<1,ad); + else + update(x,R<<1|1,ad); + push_up(R); +} +int main() +{ + int n,m,u,v,i,c,j,si,s_col; + while(scanf("%d%d",&n,&m)!=EOF) + { + if(n==0 && m==0)break; + memset(p,-1,sizeof(p)); + T=0; + for(i=1;i +#include +#include +#include +using namespace std; +const int maxn = 1e5+5; +typedef long long ll; +struct Suffix_Arr { + char s[maxn]; + int n, SA[maxn], rank[maxn], height[maxn]; + int tmp_one[maxn], tmp_two[maxn], c[maxn]; + ll f[maxn]; + void init (); + void build(int m); + void get_height(); + void solve (); + bool judge(ll m); +}AC; +int K; +int main () { + while (scanf("%d", &K) == 1 && K) { + AC.init(); + AC.build(256); + AC.get_height(); + AC.solve(); + } + return 0; +} +bool Suffix_Arr::judge(ll m) { + int t = lower_bound(f + 1, f + n + 1, m) - f; + int R = n - (f[t] - m + 1); + int len = R - SA[t] + 1; + memset(c, -1, sizeof(c)); + c[SA[t]] = len; + for (int i = t+1; i <= n; i++) { + len = min(len, height[i]); + if (len == 0) + return false; + c[SA[i]] = len; + } + int ret = 0, p = n + 1; + for (int i = 0; i < n; i++) { + if (i == p) { + ret++; + p = n + 1; + } + if (c[i] != -1) + p = min(p, i + c[i]); + if (ret >= K) + return false; + } + return true; +} +void Suffix_Arr::solve() { + ll l = 1, r = f[n]; + for (int i = 0; i < 70; i++) { + ll mid = (l + r) / 2; + if (judge(mid)) + r = mid; + else + l = mid; + } + int t = lower_bound(f + 1, f + n + 1, r) - f; + int len = n - (f[t] - r + 1); + for (int i = SA[t]; i <= len; i++) + printf("%c", s[i]); + printf("\n"); +} +void Suffix_Arr::init() { + scanf("%s", s); + n = strlen(s) + 1; +} +void Suffix_Arr::get_height() { + for (int i = 0; i < n; i++) + rank[SA[i]] = i; + int mv = height[n-1] = 0; + for (int i = 0; i < n - 1; i++) { + if (mv) mv--; + int j = SA[rank[i] - 1]; + while (s[i+mv] == s[j+mv]) + mv++; + height[rank[i]] = mv; + } + n--; + f[0] = 0; + for (int i = 1; i <= n; i++) + f[i] = f[i-1] + n - SA[i] - height[i]; +} +void Suffix_Arr::build(int m) { + int *x = tmp_one, *y = tmp_two; + for (int i = 0; i < m; i++) c[i] = 0; + for (int i = 0; i < n; i++) c[x[i] = s[i]]++; + for (int i = 1; i < m; i++) c[i] += c[i-1]; + for (int i = n - 1; i >= 0; i--) SA[--c[x[i]]] = i; + for (int k = 1; k <= n; k <<= 1) { + int mv = 0; + for (int i = n - k; i < n; i++) y[mv++] = i; + for (int i = 0; i < n; i++) if (SA[i] >= k) + y[mv++] = SA[i] - k; + for (int i = 0; i < m; i++) c[i] = 0; + for (int i = 0; i < n; i++) c[x[y[i]]]++; + for (int i = 1; i < m; i++) c[i] += c[i-1]; + for (int i = n - 1; i >= 0; i--) SA[--c[x[y[i]]]] = y[i]; + swap(x, y); + mv = 1; + x[SA[0]] = 0; + for (int i = 1; i < n; i++) + x[SA[i]] = (y[SA[i-1]] == y[SA[i]] && y[SA[i-1] + k] == y[SA[i] + k] ? mv - 1 : mv++); + if (mv >= n) + break; + m = mv; + } +} diff --git a/HDOJ/5031_autoAC.cpp b/HDOJ/5031_autoAC.cpp new file mode 100644 index 0000000..fed1c9b --- /dev/null +++ b/HDOJ/5031_autoAC.cpp @@ -0,0 +1,231 @@ +#include +#include +#include +#include +#include +using namespace std; +const int INF=1<<30; +int n,m,t; +struct Point +{ + int x,y; + Point(){} + Point(int _x, int _y) + { + x=_x; + y=_y; + } + void set(int _x, int _y) + { + x=_x; + y=_y; + } + Point operator + (const Point &b) const + { + return Point(x+b.x, y+b.y); + } + Point operator - (const Point &b) const + { + return Point(x-b.x, y-b.y); + } + int operator ^(const Point &b) const + { + return x*b.y - y*b.x; + } +}; +struct Line +{ + Point s,e; + int cover; + Line(){} + void set(Point _s, Point _e, int _c) + { + s=_s; + e=_e; + cover=_c; + } + bool operator < (const Line &b) + { + return cover < b.cover; + } +}; +Point point[5000]; +int p_point = 0; +int map[70][70]; +int min_ans = 14; +bool found = false; +void init() +{ + p_point=0; + memset(map, 0, sizeof(map)); + min_ans = 14; + found = false; + return; +} +int gcd(int x, int y) +{ + if(x=0 && p.y >= 0 && p.x <=n && p.y <=m; +} +bool CheckLine(int p1, int p2, int &cover) +{ + Point now_vec = point[p2] - point[p1]; + if(gcd( abs(now_vec.x), abs(now_vec.y)) != 1) + return false; + int now_cover = 0; + Point tmp = point[p1]; + tmp = tmp - now_vec; + while(valid(tmp)) + { + if(map[tmp.x][tmp.y] == 0) + return false; + else if(tmp.x <= point[p1].x) + return false; + now_cover ++; + tmp = tmp - now_vec; + } + tmp = point[p2]; + tmp = tmp + now_vec; + bool found_one = false; + while(valid(tmp)) + { + found_one = true; + if(map[tmp.x][tmp.y] == 0) + return false; + now_cover++; + tmp = tmp + now_vec; + } + if(!found_one) + return false; + cover = now_cover; + return true; +} +void DetermineLines(Line line[], int &p_line) +{ + int i,j; + for(i=1; i<=p_point -1;i++) + { + if(map[point[i].x][point[i].y] ==0) + continue; + for(j=i+1; j<=p_point; j++) + { + if(map[point[j].x][point[j].y]==0) + continue; + int cover; + if( CheckLine(i,j, cover) ) + { + line[++p_line].set(point[i], point[j], cover); + } + } + } + return; +} +void drop(Line l) +{ + Point p1 = l.s, p2 = l.e; + Point now_vec = p2 - p1; + Point tmp = p1; + while(valid(tmp)) + { + map[tmp.x][tmp.y] --; + tmp = tmp - now_vec; + } + tmp = p2; + while(valid(tmp)) + { + map[tmp.x][tmp.y] --; + tmp = tmp + now_vec; + } + return ; +} +void resume(Line l) +{ + Point p1 = l.s, p2 = l.e; + Point now_vec = p2 - p1; + Point tmp = p1; + while(valid(tmp)) + { + map[tmp.x][tmp.y]++; + tmp = tmp - now_vec; + } + tmp = p2; + while(valid(tmp)) + { + map[tmp.x][tmp.y]++; + tmp = tmp + now_vec; + } + return ; +} +bool cmp(const Line &a, const Line &b) +{ + return a.cover > b.cover; +} +bool check() +{ + int i; + for(i=1; i<=p_point; i++) + { + if(map[point[i].x][point[i].y] != 0) + return false; + } + return true; +} +void DFS(int depth) +{ + Line line[3000]; + int p_line = 0; + DetermineLines(line, p_line); + sort(line+1, line + p_line +1, cmp); + if(check()) + { + min_ans = depth-1; + found = true; + return ; + } + if(depth > min_ans) + return; + int i; + for(i=1; i<=min(p_line,4);i++) + { + drop(line[i]); + DFS(depth+1); + if(found) + break; + resume(line[i]); + } + return ; +} +int main() +{ + scanf("%d", &t); + int files; + for(files=1; files<=t; files++) + { + init(); + scanf("%d %d", &n, &m); + int i,j; + for(i=0; i<=n; i++) + { + for(j=0; j<=m; j++) + { + scanf("%d", &map[i][j]); + if(map[i][j]!=0) + { + point[++p_point].set(i,j); + } + } + } + DFS(1); + printf("%d\n", min_ans); + } + return 0; +} diff --git a/HDOJ/5032_autoAC.cpp b/HDOJ/5032_autoAC.cpp new file mode 100644 index 0000000..2213b6f --- /dev/null +++ b/HDOJ/5032_autoAC.cpp @@ -0,0 +1,88 @@ +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +using namespace std; +typedef long long ll; +ll bit[1010]; +void update(int pos,ll val) +{ + for(int i=pos;i<=1000;i+=i&-i) + bit[i]+=val; +} +ll psum(int pos) +{ + ll ans=0; + for(int i=pos;i>0;i-=i&-i) + ans+=bit[i]; + return ans; +} +struct Point +{ + int x,y; + bool operator <(Point one)const + { + return y*one.x<=one.y*x; + } +}point[1000010]; +struct Qu +{ + int x,y,len,no; + bool operator <(Qu one)const + { + return ll(y*one.x) +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +using namespace std; +#define MP(x,y) make_pair((x),(y)) +#define PB(x) push_back(x) +typedef __int64 LL; +const int INF = 1000111222; +const double INFF = 1e100; +const double eps = 1e-8; +const int mod = 1000000007; +const int NN = 100010; +const int MM = 400010; +struct node +{ + double h; + double x; + bool operator<(const node &tt)const + { + return x < tt.x; + } +}a[NN]; +struct Q +{ + int l,r,id; + double x; + bool operator<(const Q &tt)const + { + return x < tt.x; + } +}line[NN]; +int q[NN]; +double ans[NN]; +const double pi = acos(-1.0); +int main() +{ + int cas, ee = 0; + int i, n, m, j, j1, j2, tail; + double t, t1, t2; + scanf("%d", &cas); + while (cas--) + { + scanf("%d",&n); + for (i = 1; i <= n; i ++) + { + scanf("%lf%lf", &a[i].x, &a[i].h); + } + sort(a+1, a+1+n); + scanf("%d", &m); + for (i = 1; i <= m; i ++) + { + scanf("%lf", &line[i].x); + line[i].id = i; + } + sort(line+1, line+1+m); + q[tail = 1] = 1; + j = 2; + for (i = 1; i <= m; i ++) + { + while (j <= n && a[j].x < line[i].x) + { + while (tail > 0 && a[j].h >= a[ q[tail] ].h) + tail--; + while (tail > 1) + { + j2 = q[tail-1]; + j1 = q[tail]; + if( (a[j1].h - a[j].h) * (a[j1].x - a[j2].x) <= + (a[j2].h-a[j1].h) * (a[j].x - a[j1].x) ) + tail--; + else + break; + } + q[++tail] = j; + j++; + } + while (tail > 1) + { + j1 = q[tail-1]; + j2 = q[tail]; + if(a[j1].h/(line[i].x - a[j1].x) >= + a[j2].h/(line[i].x - a[j2].x)) + tail--; + else + break; + } + line[i].l = q[tail]; + } + q[tail = 1] = n; + j = n-1; + for (i = m; i >= 1; i --) + { + while (j >= 1 && a[j].x > line[i].x) + { + while (tail > 0 && a[j].h >= a[ q[tail] ].h) + tail--; + while (tail > 1) + { + j1 = q[tail]; + j2 = q[tail-1]; + if( (a[j1].h - a[j].h) * (a[j2].x - a[j1].x) <= + (a[j2].h-a[j1].h) * (a[j1].x - a[j].x) ) + tail--; + else + break; + } + q[++tail] = j; + j--; + } + while (tail > 1) + { + j1 = q[tail-1]; + j2 = q[tail]; + if(a[j1].h/(a[j1].x - line[i].x) >= + a[j2].h/(a[j2].x - line[i].x)) + tail--; + else + break; + } + line[i].r = q[tail]; + } + for (i = 1; i <= m; i ++) + { + t1 = a[ line[i].l ].h/( line[i].x - a[ line[i].l ].x + 0.0 ); + t2 = a[ line[i].r ].h/( line[i].x - a[ line[i].r ].x + 0.0 ); + t2 = -t2; + t = pi - atan(t1) - atan(t2); + ans[ line[i].id ] = t*180.0/pi; + } + printf("Case #%d:\n", ++ee); + for (i = 1; i <= m; i ++) + { + printf("%.10lf\n", ans[i]); + } + } + return 0; +} diff --git a/HDOJ/5035_autoAC.cpp b/HDOJ/5035_autoAC.cpp new file mode 100644 index 0000000..797c186 --- /dev/null +++ b/HDOJ/5035_autoAC.cpp @@ -0,0 +1,24 @@ +#include +#include +#include +using namespace std; +int N,T; +double sum,k; +int c; +int main(void) +{ + int cas = 1; + scanf("%d", &T); + while(T--){ + scanf("%d", &N); + sum = 0.0; + for(int i = 0; i < N; ++i){ + scanf("%lf",&k); + sum += k; + } + for(int i = 0; i < N; ++i) + scanf("%d", &c); + printf("Case #%d: %.6f\n",cas++,(N + 1.0) / sum); + } + return 0; +} diff --git a/HDOJ/5036_autoAC.cpp b/HDOJ/5036_autoAC.cpp new file mode 100644 index 0000000..c837249 --- /dev/null +++ b/HDOJ/5036_autoAC.cpp @@ -0,0 +1,42 @@ +#include +#include +#include +#include +#include +using namespace std; +const int maxn = 1005; +bitset a[maxn]; +int main() { + int t, cas = 1; + int n; + scanf("%d", &t); + while (t--) { + scanf("%d", &n); + for (int i = 0; i < n; i++) { + a[i].reset(); + a[i][i] = 1; + } + int c, x; + for (int i = 0; i < n; i++) { + scanf("%d", &c); + while (c--) { + scanf("%d", &x); + a[i][--x] = 1; + } + } + for (int i = 0; i < n; i++) + for (int j = 0; j < n; j++) + if (a[j][i]) + a[j] |= a[i]; + double ans = 0; + for (int i = 0; i < n; i++) { + c = 0; + for (int j = 0; j < n; j++) + if (a[j][i]) + c++; + ans += 1.0 / c; + } + printf("Case #%d: %.5lf\n",cas++,ans); + } + return 0; +} diff --git a/HDOJ/5037_autoAC.cpp b/HDOJ/5037_autoAC.cpp new file mode 100644 index 0000000..7ab51b5 --- /dev/null +++ b/HDOJ/5037_autoAC.cpp @@ -0,0 +1,42 @@ +#include +#include +#include +#include +#include +#define MOD 1000000007 +typedef long long ll; +using namespace std; +const int maxn=200005; +int da[maxn]; +int main() +{ + int T,n,m,l,cas=0; + scanf("%d",&T); + while(T--) + { + scanf("%d%d%d",&n,&m,&l); + for(int i=1;i<=n;i++) + scanf("%d",&da[i]); + da[++n]=m;da[0]=0; + int ans=0; + int k=l; + sort(da,da+n); + for(int i=1;i<=n;i++) + { + int x=(da[i]-da[i-1])%(l+1); + int y=(da[i]-da[i-1])/(l+1); + if(k+x>=l+1) + { + k=x; + ans+=y*2+1; + } + else if(k+x +#include +#include +#include +#include +#include +#include +using namespace std; +vector g[10005]; +int fun(int x) { + return 10000 - (100 - x) * (100 - x); +} +int main() +{ + int n, w, T, cas = 0; + scanf("%d",&T); + while(T--) { + scanf("%d",&n); + set s; + memset(g, 0, sizeof(g)); + for(int i = 0; i < n; i++) { + scanf("%d", &w); + int grade = fun(w); + s.insert(grade); + g[grade].push_back(w); + } + set ::iterator it; + vector v; + for(it = s.begin(); it != s.end(); it++) { + v.push_back(g[*it].size()); + } + sort(v.begin(), v.end()); + int ssize = v.size(); + int cnt = 0; + for(int i = ssize - 1; i >= 0; i--) { + if(v[i] == v[ssize-1]) + cnt++; + } + printf("Case #%d:\n", ++cas); + if(cnt == 1) { + for(it = s.begin(); it != s.end(); it++) + if(g[*it].size() == v[ssize-1]) { + printf("%d\n", *it); + break; + } + } + else { + if(cnt == ssize) + printf("Bad Mushroom\n"); + else { + vector ans; + for(it = s.begin(); it != s.end(); it++) { + int tmp = *it; + if(g[tmp].size() == v[ssize-1]) { + ans.push_back(tmp); + } + } + sort(ans.begin(), ans.end()); + int z = ans.size(); + for(int i = 0; i < z - 1; i++) + printf("%d ", ans[i]); + printf("%d\n", ans[z-1]); + } + } + } + return 0; +} diff --git a/HDOJ/5039_autoAC.cpp b/HDOJ/5039_autoAC.cpp new file mode 100644 index 0000000..52d1733 --- /dev/null +++ b/HDOJ/5039_autoAC.cpp @@ -0,0 +1,141 @@ +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#define inf 0x3f3f3f3f +#define Inf 0x3FFFFFFFFFFFFFFFLL +#define eps 1e-6 +#define pi acos(-1.0) +using namespace std; +typedef long long ll; +const int maxn = 30000 + 10; +struct Edge +{ + int v,color,next; + Edge(int v = 0,int color = 0,int next = 0):v(v),color(color),next(next){} +}edges[maxn<<1]; +int head[maxn],Lx[maxn],Rx[maxn],N,nEdge; +int a[maxn]; +mapmp; +void AddEdges(int u,int v,int color) +{ + edges[++nEdge] = Edge(v,color,head[u]); + head[u] = nEdge; + edges[++nEdge] = Edge(u,color,head[v]); + head[v] = nEdge; +} +void dfs(int u,int fa,int c) +{ + for(int k = head[u];k != -1;k = edges[k].next) + { + int v = edges[k].v; + if(v == fa) continue; + Lx[k/2] = ++N; + a[N] = c^edges[k].color; + dfs(v,u,c^edges[k].color); + Rx[k/2] = N; + } +} +int sum[maxn<<2],flip[maxn<<2]; +inline void PushUp(int rt) +{ + sum[rt] = sum[rt<<1] + sum[rt<<1|1]; +} +void PushDown(int l,int r,int rt) +{ + if(flip[rt]) + { + flip[rt<<1] ^= 1; + flip[rt<<1|1] ^= 1; + int m = (l + r)>>1; + sum[rt<<1] = (m - l + 1) - sum[rt<<1]; + sum[rt<<1|1] = (r - m) - sum[rt<<1|1]; + flip[rt] = 0; + } +} +void build(int l,int r,int rt) +{ + flip[rt] = 0; + if(l == r) + { + sum[rt] = a[l]; + return ; + } + int m = (l + r)>>1; + build(l,m,rt<<1); + build(m+1,r,rt<<1|1); + PushUp(rt); +} +void Update(int L,int R,int l,int r,int rt) +{ + if(l >= L && r <= R) + { + flip[rt] ^= 1; + sum[rt] = r - l + 1 - sum[rt]; + return ; + } + PushDown(l,r,rt); + int m = (l + r)>>1; + if(m >= L) Update(L,R,l,m,rt<<1); + if(m < R) Update(L,R,m+1,r,rt<<1|1); + PushUp(rt); +} +void Init() +{ + memset(head,0xff,sizeof(head)); + nEdge = -1; N = 0; + mp.clear(); +} +int main() +{ + char str[20]; + int t,tcase = 0; + scanf("%d",&t); + while(t--) + { + Init(); + int n,m; + scanf("%d",&n); + for(int i = 1;i <= n;++i) + { + scanf("%s",str); + mp[(string)str] = i; + } + int u,v,c; + for(int i = 1;i < n;++i) + { + scanf("%s",str); + u = mp[(string)str]; + scanf("%s",str); + v = mp[(string)str]; + scanf("%d",&c); + AddEdges(u,v,c); + } + dfs(1,-1,0); + build(1,N,1); + scanf("%d",&m); + printf("Case #%d:\n",++tcase); + while(m--) + { + scanf("%s",str); + if(str[0] == 'Q') + { + ll x = sum[1]; + printf("%I64d\n",x*(n - x)*2LL); + } + else + { + scanf("%d",&u); + Update(Lx[u-1],Rx[u-1],1,N,1); + } + } + } + return 0; +} diff --git a/HDOJ/5040_autoAC.cpp b/HDOJ/5040_autoAC.cpp new file mode 100644 index 0000000..f1f6357 --- /dev/null +++ b/HDOJ/5040_autoAC.cpp @@ -0,0 +1,134 @@ +#include +#include +#include +#include +#include +using namespace std ; +int n ; +int vis[505][505][4] ; +int b[505][505][4] ; +char mp[505][505] ; +int aa,bb ; +struct node +{ + int x,y ; + int step ; + friend bool operator <(node aaa,node bbb) + { + return aaa.step>bbb.step ; + } +} ; +int dx[]={-1,0,1,0,0} ; +int dy[]={0,1,0,-1,0} ; +int bfs(int x,int y) +{ + memset(vis,0,sizeof(vis)) ; + priority_queue q ; + node s ; + s.x=x ;s.y=y ;s.step=0 ; + vis[x][y][0]=1 ; + q.push(s) ; + while(!q.empty()) + { + node u=q.top() ; + //printf("%d %d %d\n",u.x,u.y,u.step) ; + if(u.x==aa && u.y==bb) + { + return u.step ; + } + q.pop() ; + for(int i=0 ;i<5 ;i++) + { + int xx=u.x+dx[i] ; + int yy=u.y+dy[i] ; + if(xx<0 || xx>=n || yy<0 || yy>=n)continue ; + if(mp[xx][yy]=='#')continue ; + node p ; + p=u ; + if(b[xx][yy][u.step%4] || b[u.x][u.y][u.step%4]) + { + if(xx==u.x && yy==u.y && !vis[xx][yy][(u.step+1)%4]) + { + p.step++ ; + vis[xx][yy][p.step%4]=1 ; + q.push(p) ; + } + else if(!vis[xx][yy][(u.step+3)%4]) + { + p.x=xx ;p.y=yy ; + p.step+=3 ; + vis[xx][yy][p.step%4]=1 ; + q.push(p) ; + } + } + else if(!vis[xx][yy][(u.step+1)%4]) + { + p.x=xx ;p.y=yy ;p.step++ ; + vis[xx][yy][p.step%4]=1 ; + q.push(p) ; + } + } + } + return -1 ; +} +int main() +{ + int T ; + scanf("%d",&T) ; + for(int cas=1 ;cas<=T ;cas++) + { + scanf("%d",&n) ; + for(int i=0 ;i=0)b[i-1][j][0]=1 ; + if(j+1=0)b[i][j-1][3]=1 ; + if(i+1=0)b[i-1][j][1]=1 ; + if(j+1=0)b[i][j-1][0]=1 ; + if(i+1=0)b[i-1][j][2]=1 ; + if(j+1=0)b[i][j-1][1]=1 ; + if(i+1=0)b[i-1][j][3]=1 ; + if(j+1=0)b[i][j-1][2]=1 ; + if(i+1 +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#define inf 0x3f3f3f3f +#define Inf 0x3FFFFFFFFFFFFFFFLL +#define eps 1e-6 +#define pi acos(-1.0) +using namespace std; +typedef long long ll; +const int maxn = 100000 + 10; +struct Node +{ + int pos,l,r,gval; + Node(int pos = 0,int l = 0,int r = 0,int gval = 0):pos(pos),l(l),r(r),gval(gval){} + bool operator < (const Node & a) const + { + if(gval != a.gval) return gval < a.gval; + if(pos != a.pos) return pos < a.pos; + return r < a.r; + } +}node[maxn*20]; +ll sum[maxn*20]; +int cnt[maxn*20]; +int a[maxn],pa[maxn],pre[maxn],val[maxn],n,tot; +int gcd(int a,int b) { return b == 0?a:gcd(b,a%b);} +vectorvt[maxn]; +void precal() +{ + for(int i = 0;i <= n;++i) vt[i].clear(); + vt[n].push_back(Node(n,n,n,a[n])); + Node ntmp; + int x; + for(int i = n - 1;i >= 1;--i) + { + int size = vt[i + 1].size(); + int cnt = 1; + vt[i].push_back(Node(i,i,i,a[i])); + for(int j = 0;j < size;++j) + { + ntmp = vt[i+1][j]; + x = gcd(a[i],ntmp.gval); + if(cnt && vt[i][cnt-1].gval == x) + vt[i][cnt - 1].r = ntmp.r; + else + vt[i].push_back(Node(i,ntmp.l,ntmp.r,x)),cnt++; + } + } + tot = 0; + for(int i = 1;i <= n;++i) + for(int j = 0;j < (int)vt[i].size();++j) + node[++tot] = Node(vt[i][j]); + sort(node + 1,node + tot + 1); + sum[0] = 0; + for(int i = 1;i <= tot;++i) + sum[i] = sum[i-1] + node[i].r - node[i].l + 1; + cnt[1] = 1; + for(int i = 2;i <= tot;++i) + cnt[i] = cnt[i-1] + (node[i].gval != node[i-1].gval); +} +int f(int l,int r) +{ + int L = 0,R = vt[l].size() - 1; + while(L < R) + { + int m = (L + R)>>1; +// cout< +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +using namespace std; +const int MOD = 1e8+9; +void Add(int &a,int b){ + a += b; + if(a >= MOD)a -= MOD; +} +int vis[10][33][22][1<<10]; +int dp[10][33][22][1<<10]; +int TT; +int prime; +int n; +int bit[10][33]; +int dfs(int id,int pos,int sum,int s){ + if(id == n){ + id = 0; + pos--; + sum = 0; + if(pos == -1)return 1; + } + if(vis[id][pos][sum][s] == TT)return dp[id][pos][sum][s]; + int end = (s&(1<= prime)break; + Add(ans,dfs(id+1,pos,sum+i,i == end? s : (s & (~(1<= 1); + int iCase = 0; + while(T--){ + iCase++; + TT++; + scanf("%d%d",&n,&prime); + assert(n >= 1 && n <= 10); + assert(prime == 2 + || prime == 3 + || prime == 5 + || prime == 7 + || prime == 11 + || prime == 13 + || prime == 17 + || prime == 19); + long long tot = 1; + for(int i = 0;i < n;i++){ + scanf("%d",&x[i]); + assert(x[i] >= 1 && x[i] <= 1000000000); + tot = tot*(1+x[i])%MOD; + } + tot -= solve(); + tot = (tot%MOD+MOD)%MOD; + printf("Case #%d: %d\n",iCase,(int)tot); + } + return 0; +} diff --git a/HDOJ/5044_autoAC.cpp b/HDOJ/5044_autoAC.cpp new file mode 100644 index 0000000..4f34e8d --- /dev/null +++ b/HDOJ/5044_autoAC.cpp @@ -0,0 +1,219 @@ +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +using namespace std; +const int MAXN = 100010; +struct Edge{ + int to,next; + int index; +}edge[MAXN*2]; +int head[MAXN],tot; +void init(){ + tot = 0; + memset(head,-1,sizeof(head)); +} +inline void addedge(int u,int v,int index){ + edge[tot].to = v; + edge[tot].next = head[u]; + edge[tot].index = index; + head[u] = tot++; +} +int F[MAXN]; +inline int find(int x){ + if(F[x] == -1)return x; + return F[x] = find(F[x]); +} +inline void bing(int x,int y){ + int t1 = find(x); + int t2 = find(y); + if(t1 != t2)F[t1] = t2; +} +long long PF[MAXN],EF[MAXN]; +struct Node{ + int id; + int v,val; + int next; + Node(int _id = 0,int _v = 0,int _val = 0){ + id = _id; + v = _v; + val = _val; + } +}query[MAXN*2]; +int h[MAXN]; +int tt; +inline void init2(){ + tt = 0; + memset(h,-1,sizeof(h)); +} +inline void add_query(int u,int v,int id,int val){ + query[tt].id = id; + query[tt].next = h[u]; + query[tt].v = v; + query[tt].val = val; + h[u] = tt++; +} +bool vis[MAXN]; +int fa[MAXN]; +bool ff[MAXN]; +int sta[MAXN]; +int cur[MAXN]; +void dfs1(int u,int pre){ + memcpy(cur,head,sizeof(head)); + memset(ff,false,sizeof(ff)); + fa[1] = -1; + int top = 0; + sta[top++] = 1; + while(top != 0){ + u = sta[top-1]; + if(!ff[u])ff[u] = true; + bool flag = false; + for(int i = cur[u];i != -1;i = edge[i].next){ + int v = edge[i].to; + if(ff[v])continue; + fa[v] = u; + sta[top++] = v; + flag = true; + cur[u] = edge[i].next; + break; + } + if(!flag){ + top--; + for(int i = h[u];i != -1;i = query[i].next){ + int v = query[i].v; + int type = query[i].id; + int w = query[i].val; + if(vis[v]){ + if(type == 1){ + PF[find(v)] -= w; + if(fa[find(v)] != -1)PF[fa[find(v)]] -= w; + PF[v] += w; + } + else { + EF[find(v)] -= 2*w; + EF[v] += w; + } + } + else { + if(type == 1)PF[v] += w; + else EF[v] += w; + } + } + if(fa[u] != -1)bing(u,fa[u]); + vis[u] = true; + } + } +} +long long a[MAXN]; +long long ans1[MAXN],ans2[MAXN]; +int gg[MAXN]; +void dfs2(int u,int pre){ + int l,r; + gg[l = r = 1] = 1; + for(;l <= r;l++) + for(int i = head[gg[l]];i != -1;i = edge[i].next){ + int v = edge[i].to; + if(v == fa[gg[l]])continue; + gg[++r] = v; + } + for(l--;l;l--){ + u = gg[l]; + for(int i = head[u];i != -1;i = edge[i].next){ + int v = edge[i].to; + if(v == fa[u])continue; + EF[u] += EF[v]; + PF[u] += PF[v]; + ans2[edge[i].index] = EF[v]; + } + ans1[u] = PF[u] + a[u]; + } +} +template +inline bool scan_d(T &ret) { + char c; int sgn; + if(c=getchar(),c==EOF) return 0; + while(c!='-'&&(c<'0'||c>'9')) c=getchar(); + sgn=(c=='-')?-1:1; + ret=(c=='-')?0:(c-'0'); + while(c=getchar(),c>='0'&&c<='9') ret=ret*10+(c-'0'); + ret*=sgn; + return 1; +} +inline void out(long long x) { + if(x>9) out(x/10); + putchar(x%10+'0'); +} +int main() +{ + int n,m; + int T; + scanf("%d",&T); + int iCase = 0; + while(T--){ + iCase++; + init(); + scan_d(n); + scan_d(m); + assert(n >= 1 && n <= 100000 && m >= 1 && m <= 100000); + memset(a,0,sizeof(a)); + int u,v,w; + for(int i = 1;i < n;i++){ + scan_d(u); + scan_d(v); + addedge(u,v,i); + addedge(v,u,i); + } + char op[20]; + init2(); + while(m--){ + scanf("%s",op); + scan_d(u); + scan_d(v); + scan_d(w); + assert(u >= 1 && u <= n); + assert(v >= 1 && v <= n); + assert(abs(w) <= 100000); + if(op[3] == '1'){ + if(u == v)a[u] += w; + else { + add_query(u,v,1,w); + add_query(v,u,1,w); + } + } + else { + if(u == v)continue; + else { + add_query(u,v,2,w); + add_query(v,u,2,w); + } + } + } + memset(PF,0,sizeof(PF)); + memset(EF,0,sizeof(EF)); + memset(F,-1,sizeof(F)); + memset(vis,false,sizeof(vis)); + dfs1(1,-1); + dfs2(1,-1); + printf("Case #%d:\n",iCase); + for(int i = 1;i <= n;i++){ + out(ans1[i]); + if(i < n)printf(" "); + else printf("\n"); + } + for(int i = 1;i < n;i++){ + out(ans2[i]); + if(i < n-1)printf(" "); + } + printf("\n"); + } + return 0; +} diff --git a/HDOJ/5045_autoAC.cpp b/HDOJ/5045_autoAC.cpp new file mode 100644 index 0000000..e237c92 --- /dev/null +++ b/HDOJ/5045_autoAC.cpp @@ -0,0 +1,52 @@ +#include +#include +#include +#include +#include +#include +using namespace std ; +typedef __int64 ll ; +double dp[1005][1050] ; +double p[15][1005] ; +int n,m ; +int main() +{ + int T ; + scanf("%d",&T) ; + for(int cas=1 ;cas<=T ;cas++) + { + scanf("%d%d",&n,&m) ; + for(int i=0 ;i +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +using namespace std; +const int maxnode = 4000; +const int MaxM = 70; +const int MaxN = 70; +int K; +struct DLX +{ + int n,m,size; + int U[maxnode],D[maxnode],R[maxnode],L[maxnode],Row[maxnode],Col[maxnode]; + int H[MaxN],S[MaxM]; + int ands,ans[MaxN]; + void init(int _n,int _m) + { + n = _n; + m = _m; + for(int i = 0;i <= m;i++) + { + S[i] = 0; + U[i] = D[i] = i; + L[i] = i-1; + R[i] = i+1; + } + R[m] = 0; L[0] = m; + size = m; + for(int i = 1;i <= n;i++) + H[i] = -1; + } + void Link(int r,int c) + { + ++S[Col[++size]=c]; + Row[size] = r; + D[size] = D[c]; + U[D[c]] = size; + U[size] = c; + D[c] = size; + if(H[r] < 0)H[r] = L[size] = R[size] = size; + else + { + R[size] = R[H[r]]; + L[R[H[r]]] = size; + L[size] = H[r]; + R[H[r]] = size; + } + } + void remove(int c) + { + for(int i = D[c];i != c;i = D[i]) + L[R[i]] = L[i], R[L[i]] = R[i]; + } + void resume(int c) + { + for(int i = U[c];i != c;i = U[i]) + L[R[i]]=R[L[i]]=i; + } + bool v[maxnode]; + int f() + { + int ret = 0; + for(int c = R[0];c != 0;c = R[c])v[c] = true; + for(int c = R[0];c != 0;c = R[c]) + if(v[c]) + { + ret++; + v[c] = false; + for(int i = D[c];i != c;i = D[i]) + for(int j = R[i];j != i;j = R[j]) + v[Col[j]] = false; + } + return ret; + } + bool Dance(int d) + { + if(d + f() > K)return false; + if(R[0] == 0)return d <= K; + int c = R[0]; + for(int i = R[0];i != 0;i = R[i]) + if(S[i] < S[c]) + c = i; + for(int i = D[c];i != c;i = D[i]) + { + remove(i); + for(int j = R[i];j != i;j = R[j])remove(j); + if(Dance(d+1))return true; + for(int j = L[i];j != i;j = L[j])resume(j); + resume(i); + } + return false; + } +}; +DLX g; +struct Point +{ + int x,y; + void input() + { + scanf("%d%d",&x,&y); + } +}city[MaxM]; +long long dis(Point a,Point b) +{ + return (long long)abs(a.x-b.x)+(long long)abs(a.y-b.y); +} +int main() +{ + int T; + int n; + scanf("%d",&T); + int iCase = 0; + while(T--) + { + iCase++; + scanf("%d%d",&n,&K); + assert(n >= 1 && n <= 60 && K >= 1 && K <= n); + for(int i = 0;i < n;i++){ + city[i].input(); + assert(abs(city[i].x) <= 1000000000); + assert(abs(city[i].y) <= 1000000000); + } + long long l = 0, r = 100000000000LL; + long long ans = 0; + while(l <= r) + { + long long mid = (l+r)/2; + g.init(n,n); + for(int i = 0;i < n;i++) + for(int j = 0;j < n;j++) + if(dis(city[i],city[j]) <= mid) + g.Link(i+1,j+1); + if(g.Dance(0)){r = mid-1;ans = mid;} + else l = mid+1; + } + printf("Case #%d: %I64d\n",iCase,ans); + } + return 0; +} diff --git a/HDOJ/5047_autoAC.cpp b/HDOJ/5047_autoAC.cpp new file mode 100644 index 0000000..fdf4a91 --- /dev/null +++ b/HDOJ/5047_autoAC.cpp @@ -0,0 +1,25 @@ +#include +using namespace std ; +typedef __int64 ll ; +const ll mod=1000000 ; +int main() +{ + int T ; + scanf("%d",&T) ; + for(int cas=1 ;cas<=T ;cas++) + { + ll n ; + scanf("%I64d",&n) ; + ll t=8*n-7 ; + ll lt=t/mod ; + ll rt=t%mod ; + lt*=n ; + rt=rt*n+1 ; + lt=lt+rt/mod ; + rt%=mod ; + printf("Case #%d: ",cas) ; + if(lt)printf("%I64d%06I64d\n",lt,rt) ; + else printf("%I64d\n",rt) ; + } + return 0 ; +} diff --git a/HDOJ/5048_autoAC.cpp b/HDOJ/5048_autoAC.cpp new file mode 100644 index 0000000..8a188a3 --- /dev/null +++ b/HDOJ/5048_autoAC.cpp @@ -0,0 +1,182 @@ +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +using namespace std; +const double eps = 1e-8; +inline double sqr(double x){return x*x;} +struct Point{ + double x,y,z; + void input(){ + scanf("%lf%lf%lf",&x,&y,&z); + assert(fabs(x) <= 10000); + assert(fabs(y) <= 10000); + assert(fabs(z) <= 10000); + } +}; +struct Line{ + Point s,e; + void input(){ + s.input(); + e.input(); + } + double len(){ + return sqrt((s.x-e.x)*(s.x-e.x)+(s.y-e.y)*(s.y-e.y)+(s.z-e.z)*(s.z-e.z)); + } +}; +struct Ellipsoid{ + double x,y,z,a,b,c; + char color[5]; + void input(){ + scanf("%lf%lf%lf%lf%lf%lf%s",&x,&y,&z,&a,&b,&c,color); + assert(fabs(x) <= 10000); + assert(fabs(y) <= 10000); + assert(fabs(z) <= 10000); + assert(a >= 1 && a <= 10000); + assert(b >= 1 && b <= 10000); + assert(c >= 1 && c <= 10000); + assert(color[0] == 'R' || color[0] == 'G' || color[0] == 'B'); + } + void output(){ + printf("%lf %lf %lf %lf %lf %lf %s\n",x,y,z,a,b,c,color); + } +}; +double calc(vectorline,vectorel){ + double ans = 0; + int sz1 = line.size(); + for(int i = 0;i < sz1;i++){ + vector >vec; + vec.push_back(make_pair(0.0,0)); + vec.push_back(make_pair(1.0,0)); + double len = line[i].len(); + if(fabs(len) < eps)continue; + double x1 = line[i].s.x; + double y1 = line[i].s.y; + double z1 = line[i].s.z; + double dx = line[i].e.x - line[i].s.x; + double dy = line[i].e.y - line[i].s.y; + double dz = line[i].e.z - line[i].s.z; + int sz = el.size(); + for(int j = 0;j < sz;j++){ + double a = sqr(dx)/sqr(el[j].a) + sqr(dy)/sqr(el[j].b) + sqr(dz)/sqr(el[j].c); + double b = 2*dx*(x1-el[j].x)/sqr(el[j].a) + + 2*dy*(y1-el[j].y)/sqr(el[j].b) + 2*dz*(z1-el[j].z)/sqr(el[j].c); + double c = sqr(x1-el[j].x)/sqr(el[j].a) + sqr(y1-el[j].y)/sqr(el[j].b) + + sqr(z1-el[j].z)/sqr(el[j].c) - 1; + double delta = b*b - 4*a*c; + if(delta < eps)continue; + double k1 = (-b+sqrt(delta))/(2*a); + double k2 = (-b-sqrt(delta))/(2*a); + if(k1 > k2)swap(k1,k2); + k1 = max(0.0,k1); + k2 = min(1.0,k2); + if(k1 >= k2)continue; + vec.push_back(make_pair(k1,1)); + vec.push_back(make_pair(k2,-1)); + } + int cnt = 0; + sort(vec.begin(),vec.end()); + int sz2 = vec.size(); + double pre = 0; + for(int j = 0;j < sz2;j++){ + if(cnt > 0) + ans += (vec[j].first - pre)*len; + pre = vec[j].first; + cnt += vec[j].second; + } + } + return ans; +} +Line line[110]; +Ellipsoid el[110]; +vectorvec1; +vectorvec2; +int main() +{ + int T; + scanf("%d",&T); + assert(T >= 1 && T <= 100); + int iCase = 0; + int n,m; + while(T--){ + iCase++; + scanf("%d%d",&n,&m); + for(int i = 0;i < n;i++)line[i].input(); + for(int i = 0;i < m;i++){ + el[i].input(); + } + vec1.clear(); + for(int i = 0;i < n;i++)vec1.push_back(line[i]); + double tot = 0; + for(int i = 0;i < n;i++)tot += line[i].len(); + vec2.clear(); + for(int i = 0;i < m;i++) + if(el[i].color[0] == 'R') + vec2.push_back(el[i]); + double R = calc(vec1,vec2); + vec2.clear(); + for(int i = 0;i < m;i++) + if(el[i].color[0] == 'G') + vec2.push_back(el[i]); + double G = calc(vec1,vec2); + vec2.clear(); + for(int i = 0;i < m;i++) + if(el[i].color[0] == 'B') + vec2.push_back(el[i]); + double B = calc(vec1,vec2); + vec2.clear(); + for(int i = 0;i < m;i++) + if(el[i].color[0] == 'R' || el[i].color[0] == 'G') + vec2.push_back(el[i]); + double RG = calc(vec1,vec2); + vec2.clear(); + for(int i = 0;i < m;i++) + if(el[i].color[0] == 'R' || el[i].color[0] == 'B') + vec2.push_back(el[i]); + double RB = calc(vec1,vec2); + vec2.clear(); + for(int i = 0;i < m;i++) + if(el[i].color[0] == 'G' || el[i].color[0] == 'B') + vec2.push_back(el[i]); + double GB = calc(vec1,vec2); + vec2.clear(); + for(int i = 0;i < m;i++) + if(el[i].color[0] == 'R' || el[i].color[0] == 'G' || el[i].color[0] == 'B') + vec2.push_back(el[i]); + double RGB = calc(vec1,vec2); + double ans1 = RGB - GB; + double ans2 = RGB - RB; + double ans3 = RGB - RG; + double ans4 = RGB - B - ans1 - ans2; + double ans5 = RGB - G - ans1 - ans3; + double ans6 = RGB - R - ans2 - ans3; + double ans7 = R + G - RG - ans4; + double aa = tot-RGB; + if(fabs(aa) < eps)aa = 0; + if(fabs(ans1) < eps)ans1 = 0; + if(fabs(ans2) < eps)ans2 = 0; + if(fabs(ans3) < eps)ans3 = 0; + if(fabs(ans4) < eps)ans4 = 0; + if(fabs(ans5) < eps)ans5 = 0; + if(fabs(ans6) < eps)ans6 = 0; + if(fabs(ans7) < eps)ans7 = 0; + printf("%.10lf\n",aa); + printf("%.10lf\n",ans1); + printf("%.10lf\n",ans2); + printf("%.10lf\n",ans3); + printf("%.10lf\n",ans4); + printf("%.10lf\n",ans5); + printf("%.10lf\n",ans6); + printf("%.10lf\n",ans7); + } + return 0; +} diff --git a/HDOJ/5049_autoAC.cpp b/HDOJ/5049_autoAC.cpp new file mode 100644 index 0000000..f7394d6 --- /dev/null +++ b/HDOJ/5049_autoAC.cpp @@ -0,0 +1,241 @@ +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +using namespace std; +const int MOD = 20140927; +struct Matrix{ + int mat[2][2]; + void init(){ + memset(mat,0,sizeof(mat)); + } + Matrix operator *(const Matrix &b)const{ + Matrix ret; + for(int i = 0;i < 2;i++) + for(int j = 0;j < 2;j++){ + ret.mat[i][j] = 0; + for(int k = 0;k < 2;k++){ + ret.mat[i][j] += (long long)mat[i][k]*b.mat[k][j]%MOD; + if(ret.mat[i][j] >= MOD) + ret.mat[i][j] -= MOD; + } + } + return ret; + } + void output(){ + printf("%d %d\n%d %d\n",mat[0][0],mat[0][1],mat[1][0],mat[1][1]); + } +}; +Matrix pow_M(Matrix A,int n){ + Matrix ret; + ret.mat[0][0] = ret.mat[1][1] = 1; + ret.mat[0][1] = ret.mat[1][0] = 0; + Matrix tmp = A; + while(n){ + if(n&1)ret = ret*tmp; + tmp = tmp*tmp; + n >>= 1; + } + return ret; +} +Matrix A[11*11*11 + 100]; +vectorvec; +Matrix B; +Matrix C; +struct Matrix2{ + int mat[2][2]; + void init(){ + memset(mat,0,sizeof(mat)); + } + Matrix2 operator *(const Matrix2 &b)const{ + Matrix2 ret; + for(int i = 0;i < 2;i++) + for(int j = 0;j < 2;j++){ + ret.mat[i][j] = 0; + for(int k = 0;k < 2;k++) + if(mat[i][k] && b.mat[k][j]) + ret.mat[i][j] = 1; + } + return ret; + } +}; +Matrix2 pow_M(Matrix2 A,int n){ + Matrix2 ret; + ret.mat[0][0] = ret.mat[1][1] = 1; + ret.mat[0][1] = ret.mat[1][0] = 0; + Matrix2 tmp = A; + while(n){ + if(n&1)ret = ret*tmp; + tmp = tmp*tmp; + n >>= 1; + } + return ret; +} +Matrix2 A2[11*11*11 + 100]; +Matrix2 B2; +Matrix2 C2; +void Add(int &a,int b){ + if(a || b)a = 1; +} +int main() +{ + for(int i = 0;i < 11*11*11;i++)A[i].init(); + for(int i = 0;i < 11*11*11;i++)A2[i].init(); + for(int x = 0;x < 11;x++) + for(int y = 0;y < 11;y++) + for(int z = 0; z < 11;z++){ + int id = x*11*11 + y*11 + z; + for(int i = 0;i < 10;i++){ + if(x != 10 && x != i)continue; + for(int j = 0;j < 10;j++){ + if(y != 10 && y != j)continue; + for(int k = 0;k < 10;k++){ + if(z != 10 && z != k)continue; + if(i + j == k)A[id].mat[0][0]++; + if(i + j == 10 + k)A[id].mat[0][1]++; + if(i + j + 1 == k)A[id].mat[1][0]++; + if(i + j + 1 == 10 + k)A[id].mat[1][1]++; + if(i + j == k)Add(A2[id].mat[0][0],1); + if(i + j == 10 + k)Add(A2[id].mat[0][1],1); + if(i + j + 1 == k)Add(A2[id].mat[1][0],1); + if(i + j + 1 == 10 + k)Add(A2[id].mat[1][1],1); + } + } + } + } + int T; + int iCase = 0; + int n1,m1,n2,m2,n3,m3; + scanf("%d",&T); + while(T--){ + iCase++; + scanf("%d%d",&n1,&m1); + assert(n1 >= 1 && n1 <= 10000000); + assert(m1 >= 0 && m1 <= n1); + mapmp1; + mapmp2; + mapmp3; + bool flag = true; + vec.clear(); + int id,x; + while(m1--){ + scanf("%d%d",&id,&x); + id = n1 - 1 - id; + vec.push_back(id); + if(mp1.find(id) != mp1.end()){ + if(mp1[id] != x)flag = false; + } + else mp1[id] = x; + } + scanf("%d%d",&n2,&m2); + assert(n2 >= 1 && n2 <= 10000000); + assert(m2 >= 0 && m2 <= n2); + while(m2--){ + scanf("%d%d",&id,&x); + id = n2 - 1 - id; + vec.push_back(id); + if(mp2.find(id) != mp2.end()){ + if(mp2[id] != x)flag = false; + } + else mp2[id] = x; + } + scanf("%d%d",&n3,&m3); + assert(n3 >= 1 && n3 <= 10000000); + assert(m3 >= 0 && m3 <= n3); + while(m3--){ + scanf("%d%d",&id,&x); + id = n3 - 1 - id; + vec.push_back(id); + if(mp3.find(id) != mp3.end()){ + if(mp3[id] != x)flag = false; + } + else mp3[id] = x; + } + if((!flag) || (n1 < max(n2,n3)) || (n1 > max(n2,n3)+1)){ + printf("Case #%d: IMPOSSIBLE\n",iCase); + continue; + } + vec.push_back(n2-1); + vec.push_back(n3-1); + sort(vec.begin(),vec.end()); + vec.erase(unique(vec.begin(),vec.end()),vec.end()); + int mn = max(n2,n3); + B.init(); + B.mat[0][0] = B.mat[1][1] = 1; + B2.init(); + B2.mat[0][0] = B2.mat[1][1] = 1; + if(vec[0] > 0)B = B * pow_M(A[10*11*11+10*11+10],vec[0]); + if(vec[0] > 0)B2 = B2 * pow_M(A2[10*11*11+10*11+10],vec[0]); + int sz = vec.size(); + for(int i = 0;i < sz;i++){ + if(i > 0){ + B = B * pow_M(A[10*11*11+10*11+10],vec[i]-vec[i-1]-1); + } + int x,y,z; + if(mp2.find(vec[i]) == mp2.end())x = 10; + else x = mp2[vec[i]]; + if(vec[i] >= n2)x = 0; + if(mp3.find(vec[i]) == mp3.end())y = 10; + else y = mp3[vec[i]]; + if(vec[i] >= n3)y = 0; + if(mp1.find(vec[i]) == mp1.end())z = 10; + else z = mp1[vec[i]]; + if(vec[i] >= n1)z = 0; + if(vec[i] != n2-1 && vec[i] != n3-1){ + B = B * A[x*11*11+y*11+z]; + B2 = B2 * A2[x*11*11+y*11+z]; + } + else { + C.init(); + C2.init(); + for(int p = 0;p < 10;p++) + for(int q = 0;q < 10;q++) + for(int r = 0;r < 10;r++){ + if(x != 10 && p != x)continue; + if(y != 10 && q != y)continue; + if(z != 10 && r != z)continue; + if(n2 != 1 && vec[i] == n2-1 && p == 0)continue; + if(n3 != 1 && vec[i] == n3-1 && q == 0)continue; + if(vec[i] >= n2 && p != 0)continue; + if(vec[i] >= n3 && q != 0)continue; + if(p+q == r)C.mat[0][0]++; + if(p+q == r+10)C.mat[0][1]++; + if(p+q+1 == r)C.mat[1][0]++; + if(p+q+1 == r + 10)C.mat[1][1]++; + if(p+q == r)Add(C2.mat[0][0],1); + if(p+q == r+10)Add(C2.mat[0][1],1); + if(p+q+1 == r)Add(C2.mat[1][0],1); + if(p+q+1 == r + 10)Add(C2.mat[1][1],1); + } + B = B*C; + B2 = B2*C2; + } + } + int ans = 0; + int ans2 = 0; + if(n1 == max(n2,n3)){ + ans = B.mat[0][0]; + ans2 = B2.mat[0][0]; + } + else{ + if(mp1.find(n1-1) != mp1.end() && mp1[n1-1] != 1){ + printf("Case #%d: IMPOSSIBLE\n",iCase); + continue; + } + ans = B.mat[0][1]; + ans2 = B2.mat[0][1]; + } + if(ans2 == 0)printf("Case #%d: IMPOSSIBLE\n",iCase); + else printf("Case #%d: %d\n",iCase,ans); + } + return 0; +} diff --git a/HDOJ/5050_autoAC.cpp b/HDOJ/5050_autoAC.cpp new file mode 100644 index 0000000..52a8479 --- /dev/null +++ b/HDOJ/5050_autoAC.cpp @@ -0,0 +1,106 @@ +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +using namespace std; +struct BigNum{ + int a[10100]; + int n; + void input(char str[]){ + n = strlen(str); + for(int i = 0;i < n;i++) + a[i] = str[n-1-i]-'0'; + } + bool operator <(const BigNum &b)const{ + if(n < b.n)return true; + if(n > b.n)return false; + for(int i = n-1;i >= 0;i--){ + if(a[i] < b.a[i])return true; + if(a[i] > b.a[i])return false; + } + return true; + } + BigNum operator -(const BigNum &b)const{ + BigNum ret; + ret.n = n; + int mu = 0; + for(int i = 0;i < n;i++){ + int tmp; + if(i < b.n)tmp = a[i] - b.a[i] - mu; + else tmp = a[i] - mu; + if(tmp >= 0){ + mu = 0; + ret.a[i] = tmp; + } + else { + mu = 1; + ret.a[i] = tmp+2; + } + } + while(ret.n > 0 && ret.a[ret.n-1] == 0)ret.n--; + return ret; + } + BigNum div2(){ + BigNum ret; + ret.n = n-1; + for(int i = 0;i < n-1;i++) + ret.a[i] = a[i+1]; + return ret; + } + void output(){ + for(int i = n-1;i >= 0;i--) + printf("%d",a[i]); + } +}; +void gcd(BigNum a,BigNum b){ + int c2 = 0; + while(a.n && b.n){ + if(a.a[0]){ + if(b.a[0]){ + if(b < a)a = a-b; + else b = b-a; + } + else b = b.div2(); + } + else { + if(b.a[0])a = a.div2(); + else{ + a = a.div2(); + b = b.div2(); + c2++; + } + } + } + if(a.n)a.output(); + else b.output(); + while(c2--){ + printf("0"); + } + printf("\n"); +} +char str[10010]; +BigNum a,b,c; +int main() +{ + int T; + scanf("%d",&T); + int iCase = 0; + while(T--){ + iCase++; + scanf("%s",str); + a.input(str); + scanf("%s",str); + b.input(str); + printf("Case #%d: ",iCase); + gcd(a,b); + } + return 0; +} diff --git a/HDOJ/5051_autoAC.cpp b/HDOJ/5051_autoAC.cpp new file mode 100644 index 0000000..c8d2a48 --- /dev/null +++ b/HDOJ/5051_autoAC.cpp @@ -0,0 +1,55 @@ +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +using namespace std; +int main() +{ + int T; + int iCase = 0; + scanf("%d",&T); + int n,b,q; + while(T--){ + iCase++; + scanf("%d%d%d",&n,&b,&q); + printf("Case #%d: ",iCase); + if(q == 1){ + bool flag = false; + while(b){ + if(n == b){ + flag = true; + break; + } + b /= 10; + } + if(flag)printf("1.00000\n"); + else printf("0.00000\n"); + } + else if(q == 10 || q == 100 || q == 1000){ + b *= 100000; + bool flag = false; + while(b){ + if(n == b){ + flag = true; + break; + } + b /= 10; + } + if(flag)printf("1.00000\n"); + else printf("0.00000\n"); + } + else { + double ans = (log(n+1)-log(n))/log(10); + printf("%.5lf\n",ans); + } + } + return 0; +} diff --git a/HDOJ/5052_autoAC.cpp b/HDOJ/5052_autoAC.cpp new file mode 100644 index 0000000..82a99c3 --- /dev/null +++ b/HDOJ/5052_autoAC.cpp @@ -0,0 +1,186 @@ +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +using namespace std; +const int MAXN = 50010; +const int INF = 0x3f3f3f3f; +struct Node *null; +struct Node{ + Node *fa,*ch[2]; + int val; + int Max,Min; + int mm; + int rmm; + int rev,add; + inline void clear(int _val){ + fa = ch[0] = ch[1] = null; + val = Max = Min = _val; + mm = 0; + rmm = 0; + rev = 0; + add = 0; + } + inline void push_up(){ + if(this == null)return; + mm = 0; + mm = max(mm,ch[0]->mm); + mm = max(mm,ch[1]->mm); + mm = max(mm,max(val,ch[1]->Max)-ch[0]->Min); + mm = max(mm,ch[1]->Max-min(ch[0]->Min,val)); + rmm = 0; + rmm = max(rmm,ch[0]->rmm); + rmm = max(rmm,ch[1]->rmm); + rmm = max(rmm,max(val,ch[0]->Max)-ch[1]->Min); + rmm = max(rmm,ch[0]->Max-min(ch[1]->Min,val)); + Max = max(val,max(ch[0]->Max,ch[1]->Max)); + Min = min(val,min(ch[0]->Min,ch[1]->Min)); + } + inline void setc(Node *p,int d){ + ch[d] = p; + p->fa = this; + } + inline bool d(){ + return fa->ch[1] == this; + } + inline bool isroot(){ + return fa == null || fa->ch[0] != this && fa->ch[1] != this; + } + inline void flip(){ + if(this == null)return; + swap(ch[0],ch[1]); + swap(mm,rmm); + rev ^= 1; + } + inline void update_add(int w){ + if(this == null)return; + val += w; + Min += w; + Max += w; + add += w; + } + inline void push_down(){ + if(this == null)return; + if(rev){ + ch[0]->flip(); ch[1]->flip(); rev = 0; + } + if(add){ + ch[0]->update_add(add);ch[1]->update_add(add); + add = 0; + } + } + inline void go(){ + if(!isroot())fa->go(); + push_down(); + } + inline void rot(){ + Node *f = fa, *ff = fa->fa; + int c = d(), cc = fa->d(); + f->setc(ch[!c],c); + this->setc(f,!c); + if(ff->ch[cc] == f)ff->setc(this,cc); + else this->fa = ff; + f->push_up(); + } + inline Node* splay(){ + go(); + while(!isroot()){ + if(!fa->isroot()) + d()==fa->d() ? fa->rot() : rot(); + rot(); + } + push_up(); + return this; + } + inline Node* access(){ + for(Node *p = this, *q = null; p != null; q = p, p = p->fa){ + p->splay()->setc(q,1); + p->push_up(); + } + return splay(); + } + inline void make_root(){ + access()->flip(); + } +}; +Node pool[MAXN],*tail; +Node *node[MAXN]; +struct Edge{ + int to,next; +}edge[MAXN*2]; +int head[MAXN],tot; +void init(){ + tot = 0; + memset(head,-1,sizeof(head)); +} +inline void addedge(int u,int v){ + edge[tot].to = v; + edge[tot].next = head[u]; + head[u] = tot++; +} +int g[MAXN]; +int fa[MAXN]; +void bfs(int s){ + int l,r; + g[l=r=1] = s; + fa[s] = s; + while(l <= r){ + int u = g[l++]; + for(int i = head[u];i != -1;i = edge[i].next){ + int v = edge[i].to; + if(v == fa[u])continue; + fa[v] = u; + node[v]->fa = node[u]; + g[++r] = v; + } + } +} +int main() +{ + int T; + int n,m; + scanf("%d",&T); + assert(T > 0 && T <= 10); + while(T--){ + scanf("%d",&n); + tail = pool; + null = tail++; + null->fa = null->ch[0] = null->ch[1] = null; + null->Max = -INF; + null->Min = INF; + null->mm = 0; + null->add = null->rev = 0; + int w; + for(int i = 1;i <= n;i++){ + scanf("%d",&w); + node[i] = tail++; + node[i]->clear(w); + } + init(); + int u,v; + for(int i = 1;i < n;i++){ + scanf("%d%d",&u,&v); + addedge(u,v); + addedge(v,u); + } + bfs(1); + scanf("%d",&m); + while(m--){ + scanf("%d%d%d",&u,&v,&w); + node[u]->make_root(); + node[v]->access(); + printf("%d\n",node[v]->mm); + node[v]->update_add(w); + } + } + return 0; +} diff --git a/HDOJ/5053_autoAC.cpp b/HDOJ/5053_autoAC.cpp new file mode 100644 index 0000000..bb36b49 --- /dev/null +++ b/HDOJ/5053_autoAC.cpp @@ -0,0 +1,28 @@ +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +using namespace std; +int main() +{ + int T; + int iCase = 0; + scanf("%d",&T); + long long a,b; + while(T--){ + iCase++; + scanf("%I64d%I64d",&a,&b); + a--; + long long ans = (b*(b+1)/2)*(b*(b+1)/2) - (a*(a+1)/2)*(a*(a+1)/2); + printf("Case #%d: %I64d\n",iCase,ans); + } + return 0; +} diff --git a/HDOJ/5054_autoAC.cpp b/HDOJ/5054_autoAC.cpp new file mode 100644 index 0000000..8abf767 --- /dev/null +++ b/HDOJ/5054_autoAC.cpp @@ -0,0 +1,15 @@ +#include +#include +using namespace std; +int main() +{ + int N,M,x,y; + while(scanf("%d%d%d%d",&N,&M,&x,&y)!=EOF) + { + if(2*x==N&&2*y==M) + printf("YES\n"); + else + printf("NO\n"); + } + return 0; +} diff --git a/HDOJ/5055_autoAC.cpp b/HDOJ/5055_autoAC.cpp new file mode 100644 index 0000000..94b7f9d --- /dev/null +++ b/HDOJ/5055_autoAC.cpp @@ -0,0 +1,48 @@ +#include +#include +#include +#include +#include +using namespace std; +int str[120]; +int main() +{ + int n,i,res; + while(scanf("%d",&n)!=EOF) + { + res=10; + for(i=0;istr[i]) + res=str[i]; + } + if(res==10){ + printf("-1\n"); + continue; + } + sort(str,str+n,greater()); + int fir=-1,st=res; + for(i=0;i +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#define LL long long +#define lowbit(x) ((x) & (-x)) +#define MP(a, b) make_pair(a, b) +#define MS(arr, num) memset(arr, num, sizeof(arr)) +#define PB push_back +#define F first +#define S second +#define ROP freopen("input.txt", "r", stdin); +#define BitCount(x) __builtin_popcount(x) +const double PI = acos(-1.0); +const int INF = 0x3f3f3f3f; +using namespace std; +const int MAXN = 1e5 + 100; +const int MOD = 20071027; +typedef pair pii; +typedef vector::iterator viti; +typedef vector::iterator vitii; +char str[MAXN]; +int cnt[30]; +int main() +{ + //ROP; + int n, i, j, last, T, k; + scanf("%d", &T); + while (T--) + { + MS(cnt, 0); + int pos = 1; + scanf("%s", str + 1); + scanf("%d", &k); + int len = strlen(str + 1); + LL ans = 0; + for (i = 1; i <= len; i++) + { + cnt[str[i] - 'a']++; + while (cnt[str[i] - 'a'] > k) + { + cnt[str[pos] - 'a']--; + pos++; + } + ans += i - pos + 1; + } + cout << ans << endl; + } + return 0; +} diff --git a/HDOJ/5057_autoAC.cpp b/HDOJ/5057_autoAC.cpp new file mode 100644 index 0000000..7497b44 --- /dev/null +++ b/HDOJ/5057_autoAC.cpp @@ -0,0 +1,65 @@ +#include +#include +#include +#include +#include +#define ll long long +using namespace std; +const int maxn=100005; +int n,m; +int digit[maxn][10]; +int block[400][10][10]; +int X,Y,L,R,D,P; +int main() +{ + int x; + char str[10]; + int t; + scanf("%d",&t); + while(t--) { + scanf("%d%d",&n,&m); + memset(block,0,sizeof(block)); + for(int i=1;i<=n;i++) { + scanf("%d",&x); + int b=(i>>8); + for(int j=1;j<=10;j++) { + digit[i][j]=x%10; + block[b][j][x%10]++; + x/=10; + } + } + for(int i=0;i>8); + for(int j=1;j<=10;j++) { + block[b][j][digit[X][j]]--; + digit[X][j]=Y%10; + block[b][j][Y%10]++; + Y/=10; + } + } + else { + scanf("%d%d%d%d",&L,&R,&D,&P); + int bl=((L-1)>>8)+1,br=((R+1)>>8)-1; + int ans=0; + if(bl<=br) { + for(int i=bl;i<=br;i++) + ans+=block[i][D][P]; + for(int i=L;i<(bl<<8);i++) + ans+=(digit[i][D]==P); + for(int i=((br+1)<<8);i<=R;i++) + ans+=(digit[i][D]==P); + } + else { + for(int i=L;i<=R;i++) { + ans+=(digit[i][D]==P); + } + } + printf("%d\n",ans); + } + } + } + return 0; +} diff --git a/HDOJ/5058_autoAC.cpp b/HDOJ/5058_autoAC.cpp new file mode 100644 index 0000000..8c3a1ae --- /dev/null +++ b/HDOJ/5058_autoAC.cpp @@ -0,0 +1,47 @@ +#include +#include +#include +using namespace std; +int main() +{ + sets1,s2; + int n; + while(~scanf("%d",&n)) + { + s1.clear(); + s2.clear(); + int tt; + for(int i = 0; i < n; i++) + { + scanf("%d",&tt); + s1.insert(tt); + } + for(int i = 0; i < n; i++) + { + scanf("%d",&tt); + s2.insert(tt); + } + if(s1.size() != s2.size()) + { + printf("NO\n"); + continue; + } + int flag = 0; + set::iterator it1, it2; + for(it1 = s1.begin(),it2 = s2.begin(); it1!=s1.end()&&it2!=s2.end(); it1++,it2++) + { + if(*it1 != *it2) + { + flag = 1; + break; + } + } + if(flag) + { + printf("NO\n"); + } + else + printf("YES\n"); + } + return 0; +} diff --git a/HDOJ/5059_autoAC.cpp b/HDOJ/5059_autoAC.cpp new file mode 100644 index 0000000..f1cfa4b --- /dev/null +++ b/HDOJ/5059_autoAC.cpp @@ -0,0 +1,43 @@ +#include +#include +#include +char S[200]; +char C[200]; +int len; +long long a,b; +int getans(char *A) +{ + int i; + int lena=strlen(A); + if(lena==0) return 0; + if(lena!=1&&A[0]=='0') return 0; + for(i=0;i11||len==0) { printf("NO\n");continue;} + if(len==11&&S[0]!='-') { printf("NO\n");continue;} + if(S[0]=='-') + ans=getans(S+1); + else ans=getans(S); + if(!ans) { printf("NO\n");continue;} + else + { + k=strtoll(S,NULL,10); + if(a<=k&&k<=b) printf("YES\n"); + else printf("NO\n"); + } + memset(S,0,sizeof(S)); + } + return 0; +} diff --git a/HDOJ/5060_autoAC.cpp b/HDOJ/5060_autoAC.cpp new file mode 100644 index 0000000..204c8cf --- /dev/null +++ b/HDOJ/5060_autoAC.cpp @@ -0,0 +1,66 @@ +#include +#include +#include +#include +#include +#include +using namespace std; +const double pi=3.14159265358979,eps=1e-7; +double r,hr,hz; +double f(double n) +{ + return pi*(r*r-n*n); +} +double simpson(double a,double b) +{ + return (b-a)/6.0*(f(a)+4*f((a+b)/2.0)+f(b)); +} +double cal(double a,double b) +{ + double sum=simpson(a,b),mid=(a+b)/2.0; + double t=simpson(a,mid)+simpson(mid,b); + if(fabs(t-sum)=r&&hz>=r) + { + v=4.0/3.0*pi*r*r*r; + hv=2*pi*hr*hr*hz; + printf("%.6lf\n",v/hv); + continue; + } + if(hr>=r&&hz=hr*hr+hz*hz) + { + v=4.0/3.0*pi*r*r*r; + hv=2*pi*hr*hr*hz; + printf("%.6lf\n",hv/v); + continue; + } + if(hr=r) + { + v=4.0/3.0*pi*r*r*r; + double t=2*cal(sqrt(r*r-hr*hr),r)+2*sqrt(r*r-hr*hr)*pi*hr*hr; + hv=2*pi*hr*hr*hz; + printf("%.6lf\n",t/(hv+v-t)); + continue; + } + v=4.0/3.0*pi*r*r*r; + hv=2*pi*hr*hr*hz; + double t=2*cal(sqrt(r*r-hr*hr),hz)+2*sqrt(r*r-hr*hr)*pi*hr*hr; + printf("%.6lf\n",t/(hv+v-t)); + } + return 0; +} diff --git a/HDOJ/5062_autoAC.cpp b/HDOJ/5062_autoAC.cpp new file mode 100644 index 0000000..5730ae3 --- /dev/null +++ b/HDOJ/5062_autoAC.cpp @@ -0,0 +1,15 @@ +#include +#include +using namespace std; +int main() +{ + int T,N; + int array[8] = {1,9,18,54,90,174,258}; + scanf("%d",&T); + while(T--) + { + scanf("%d",&N); + printf("%d\n",array[N]); + } + return 0; +} diff --git a/HDOJ/5063_autoAC.cpp b/HDOJ/5063_autoAC.cpp new file mode 100644 index 0000000..7c5a302 --- /dev/null +++ b/HDOJ/5063_autoAC.cpp @@ -0,0 +1,70 @@ +#include +#include +#include +#include +#define MOD 1000000007 +#define MAX 200007 +using namespace std; +typedef long long LL; +LL a[MAX]; +int p,cnt1,cnt2; +int t,n,m; +int bf1 ( int i ) +{ + if ( i > (n+1)/2 ) + { + int temp = i*2-n-1; + if ( n&1 ) return temp; + else return temp+1; + } + else return i*2-1; +} +int bf2 ( int i ) +{ + return n+1-i; +} +void f3 ( ) +{ + p++; +} +LL ans[107]; +char s[5]; +int q[MAX],x; +int query ( int x , int cnt ) +{ + for ( int i = cnt-1 ; i >= 0 ; i-- ) + if ( q[i] == 1 ) x = bf1(x); + else x = bf2(x); + return x; +} +int main ( ) +{ + scanf ( "%d" , &t ); + while ( t-- ) + { + p = cnt1 = cnt2 = 0; + scanf ( "%d%d" , &n , &m ); + for ( int i = 1 ; i <= n ; i++ ) + a[i] = i; + for ( int i = 1 ; i <= m ; i++ ) + { + scanf ( "%s" , s ); + scanf ( "%d" , &x ); + if ( s[0] == 'O' ) + { + if ( x == 3 ) f3( ); + else q[cnt1++] = x; + } + else + { + int id = query ( x , cnt1 ); + LL tx = a[id]; + for ( int i = 0 ; i < p ; i++ ) + tx *= tx , tx %= MOD; + ans[cnt2++] = tx; + } + } + for ( int i = 0 ; i < cnt2 ; i++ ) + printf ( "%I64d\n" , ans[i] ); + } +} diff --git a/HDOJ/5064_autoAC.cpp b/HDOJ/5064_autoAC.cpp new file mode 100644 index 0000000..93a10cd --- /dev/null +++ b/HDOJ/5064_autoAC.cpp @@ -0,0 +1,52 @@ +#include +#include +#include +#include +#include +using namespace std; +#define N 10000000 +#define M 3000 +int a[N],dp[M][M],s[M],num[M]; +int n,m; +int main() +{ + int t; + cin>>t; + while(t--) + { + scanf("%d%d",&n,&m); + for(int i=0;i=(num[i]-num[k])&&k>=0) + { + ma=max(ma,dp[k][i]); + k--; + } + dp[i][j]=ma+1; + ans=max(ans,dp[i][j]); + } + } + printf("%d\n",ans); + } + return 0; +} diff --git a/HDOJ/5065_autoAC.cpp b/HDOJ/5065_autoAC.cpp new file mode 100644 index 0000000..b4e47b8 --- /dev/null +++ b/HDOJ/5065_autoAC.cpp @@ -0,0 +1,51 @@ +#include +#include +#include +using namespace std; +int A,B,y; +double ans=0; +double inline f(double x) +{ + return A*x*x-(B*sin(x)+y); +} +double inline absf(double x) +{ + if(f(x)<0)return -f(x); + return f(x); +} +bool findans(double l,double r) +{ + if(f(l)*f(r)>0)return 0; + while(r-l>0.00000001) + { + double mid1=l+(r-l)/3,mid2=r-(r-l)/3; + if(absf(mid1)<=absf(mid2)) + r=mid2; + else + l=mid1; + } + ans=l; + return 1; +} +int main() +{ + int T; + scanf("%d",&T); + while(T--) + { + scanf("%d%d%d",&A,&B,&y); + bool marks=0;ans=0; + for(double x=0;x<50;x=x+0.3) + { + if(findans(x,x+0.3)) + { + marks=1;break; + } + } + if(marks) + printf("%.5lf\n",ans); + else + printf("error\n"); + } + return 0; +} diff --git a/HDOJ/5066_autoAC.cpp b/HDOJ/5066_autoAC.cpp new file mode 100644 index 0000000..038c8d8 --- /dev/null +++ b/HDOJ/5066_autoAC.cpp @@ -0,0 +1,9 @@ +#include +using namespace std; +int main(void) +{ + int v,v0; + while(~scanf("%d %d", &v,&v0)) + printf("%d\n",2 * v - v0); + return 0; +} diff --git a/HDOJ/5067_autoAC.cpp b/HDOJ/5067_autoAC.cpp new file mode 100644 index 0000000..e56f1be --- /dev/null +++ b/HDOJ/5067_autoAC.cpp @@ -0,0 +1,76 @@ +#include "cstdio" +#include "iostream" +#include "cstring" +#include "vector" +#include "queue" +using namespace std; +#define inf 0x3f3f3f3f +int area[55][55],dp[1<<15][15],vis[55][55],dis[55][55],dir[4][2]={-1,0,1,0,0,-1,0,1},n,m,g; +struct status +{ + int x,y,dep; + status(int x,int y,int dep):x(x),y(y),dep(dep) {} +}; +int bfs(status s,status e) +{ + memset(vis,0,sizeof(vis)); + vis[s.x][s.y]=true; + queue Q; + Q.push(status(s.x,s.y,0)); + while(!Q.empty()) + { + status t=Q.front();Q.pop(); + for(int s=0;s<4;s++) + { + int X=t.x+dir[s][0],Y=t.y+dir[s][1]; + if(X<1||X>n||Y<1||Y>m||vis[X][Y]) continue; + vis[X][Y]=true; + if(X==e.x&&Y==e.y) return t.dep+1; + Q.push(status(X,Y,t.dep+1)); + } + } +} +int main() +{ + while(scanf("%d%d",&n,&m)!=EOF) + { + vector stone; + stone.push_back(status(1,1,0)); + for(int i=1;i<=n;i++) + for(int j=1;j<=m;j++) + { + scanf("%d",&g); + if(i==1&&j==1) continue; + if(g) stone.push_back(status(i,j,0)); + } + for(int i=0;i +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +using namespace std ; +#define INT __int64 +#define L(x) (x * 2) +#define R(x) (x * 2 + 1) +const int INF = 0x3f3f3f3f ; +const double esp = 0.0000000001 ; +const double PI = acos(-1.0) ; +const INT mod = 1000000007 ; +const int MY = 1400 + 5 ; +const int MX = 50000 + 5 ; +int n ,m ; +struct node +{ + int le ,rt ; + INT p[2][2] ; +}T[MX*8] ; +node operator *(const node& a ,const node& b) +{ + node c ; + memset(c.p ,0 ,sizeof(c.p)) ; + for(int i = 0 ;i < 2 ; ++i) + for(int k = 0 ;k < 2 ; ++k) + if(a.p[i][k]) + for(int j = 0 ;j < 2 ; ++j) + c.p[i][j] = (c.p[i][j] + a.p[i][k]*b.p[k][j])%mod ; + return c ; +} +void build(int x ,int le ,int rt) +{ + T[x].le = le ; T[x].rt = rt ; + if(le == rt) + { + for(int i = 0 ;i < 2 ; ++i) + for(int j = 0 ;j < 2 ; ++j) + T[x].p[i][j] = 1 ; + return ; + } + int Mid = (le + rt)>>1 ; + build(L(x) ,le ,Mid) ; + build(R(x) ,Mid+1 ,rt) ; + T[x] = T[L(x)] * T[R(x)] ; + T[x].le = le ; T[x].rt = rt ; +} +void update(int x ,int pos ,int i ,int j) +{ + if(T[x].le == T[x].rt) + { + T[x].p[i][j] ^= 1 ; + return ; + } + int Mid = (T[x].le + T[x].rt)>>1 ; + if(pos <= Mid) update(L(x) ,pos ,i ,j) ; + else update(R(x) ,pos ,i ,j) ; + int le = T[x].le ,rt = T[x].rt ; + T[x] = T[L(x)] * T[R(x)] ; + T[x].le = le ; T[x].rt = rt ; +} +node section(int x ,int le ,int rt) +{ + if(T[x].le == le && T[x].rt == rt) + return T[x] ; + int Mid = (T[x].le + T[x].rt)>>1 ; + if(rt <= Mid) return section(L(x) ,le ,rt) ; + else if(le > Mid) return section(R(x) ,le ,rt) ; + else + return section(L(x) ,le ,Mid)*section(R(x) ,Mid+1 ,rt) ; +} +int main() +{ + //freopen("input.txt" ,"r" ,stdin) ; + int p ,u ,v ,z ; + while(~scanf("%d%d" ,&n ,&m)) + { + build(1 ,1 ,n) ; + for(int i = 0 ;i < m ; ++i) + { + scanf("%d" ,&p) ; + if(p) + { + scanf("%d%d%d" ,&u ,&v ,&z) ; + update(1 ,u ,v-1 ,z-1) ; + } + else + { + scanf("%d%d" ,&u ,&v) ; + node ans = section(1 ,u ,v-1) ; + printf("%I64d\n" ,(ans.p[0][0] + ans.p[0][1] + ans.p[1][0] + ans.p[1][1])%mod) ; + } + } + } + return 0 ; +} diff --git a/HDOJ/5069_autoAC.cpp b/HDOJ/5069_autoAC.cpp new file mode 100644 index 0000000..5e5b96b --- /dev/null +++ b/HDOJ/5069_autoAC.cpp @@ -0,0 +1,136 @@ +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#define LL long long +#define mod 1000000007 +#define maxn 200010 +#define INF 0x3f3f3f3f +using namespace std; +struct node +{ + int u,id; + bool operator<(const node&s)const + { + return u < s.u ; + } +}; +struct SAM +{ + SAM *pre,*son[4] ; + int len ,vi; + void init() + { + pre=NULL ; + memset(son,NULL,sizeof(son)) ; + vi=0; + } +}que[maxn*2],*root,*tail,*b[maxn]; +int tot,ans[maxn] ,cnt[maxn],s[maxn]; +int id(char a ) +{ + if(a=='A') return 0 ; + else if(a=='C') return 1 ; + else if(a=='G') return 2 ; + return 3 ; +} +vectorqe[maxn] ; +void add(int c ,int l) +{ + que[tot].init(); + SAM *p = tail,*np=&que[tot++] ; + np->len=l;tail=np ; + while(p&&p->son[c]==NULL)p->son[c]=np,p=p->pre ; + if(p==NULL) np->pre = root ; + else + { + SAM *q = p->son[c] ; + if(p->len+1==q->len)np->pre = q ; + else + { + que[tot].init(); + SAM *nq = &que[tot++] ; + *nq=*q ; + nq->len = p->len+1; + np->pre=q->pre=nq; + while(p&&p->son[c]==q) p->son[c]=nq,p=p->pre; + } + } +} +char str[maxn] ; +int main() +{ + int i , j ,k ,len,n , m; + int u,v ; + node a ; + while(scanf("%d%d",&n,&m) != EOF) + { + for(i=1;i<=n;i++) + qe[i].clear(); + len=1; + for( i = 1 ; i <= n ;i++) + { + scanf("%s",str+len) ; + k = strlen(str+len) ; + s[i]=len; + cnt[i]=k; + len += k+1 ; + } + for( i = 1 ; i <= m ;i++) + { + scanf("%d%d",&u,&v) ; + a.id = i ; + a.u = v ; + qe[u].push_back(a); + } + for( i = 1 ; i <= n ;i++) + { + if(qe[i].size()==0) continue ; + sort(qe[i].begin(),qe[i].end()); + tot=0; + que[0].init(); + root=tail=&que[tot++]; + k=1; + for( j = s[i] ; j < s[i]+cnt[i];j++){ + add(id(str[j]),k++); + } + SAM *p= tail; + while(p != NULL ) + { + p->vi = true; + p=p->pre; + } + for( j = 0 ; j < qe[i].size();j++){ + a=qe[i][j] ; + ans[a.id]=0; + if(j&&a.u==qe[i][j-1].u) + { + ans[a.id]=ans[qe[i][j-1].id]; + continue ; + } + p = root ; + int tmp=0; + for( k = s[a.u] ; k < s[a.u]+cnt[a.u];k++) + { + int v = id(str[k]) ; + if(p->son[v]==NULL) break ; + p=p->son[v] ; + tmp++; + if(p->vi) + ans[a.id]=max(ans[a.id],tmp); + } + } + } + for( i = 1 ; i <= m ;i++) + printf("%d\n",ans[i]); + } + return 0 ; +} diff --git a/HDOJ/5071_autoAC.cpp b/HDOJ/5071_autoAC.cpp new file mode 100644 index 0000000..f49d69a --- /dev/null +++ b/HDOJ/5071_autoAC.cpp @@ -0,0 +1,148 @@ +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +using namespace std; +int sta[5010]; +int cnt; +int top; +int index; +mapmp; +void gao1(int u){ + for(int i = 1;i <= cnt;i++) + if(sta[i] == u){ + printf("Operation #%d: same priority.\n",index); + return; + } + printf("Operation #%d: success.\n",index); + sta[++cnt] = u; + mp[u] = 0; +} +void gao2(int u){ + for(int i = 1;i <= cnt;i++) + if(sta[i] == u){ + if(top != -1){ + if(top == u){ + top = -1; + } + } + for(int j = i;j < cnt;j++)sta[j] = sta[j+1]; + cnt--; + printf("Operation #%d: close %d with %I64d.\n",index,u,mp[u]); + return; + } + printf("Operation #%d: invalid priority.\n",index); +} +void gao3(int w){ + if(cnt == 0){ + printf("Operation #%d: empty.\n",index); + return; + } + if(top != -1)mp[top] += w; + else mp[sta[1]] += w; + printf("Operation #%d: success.\n",index); +} +void gao4(int x){ + if(x < 1 || x > cnt){ + printf("Operation #%d: out of range.\n",index); + return; + } + int tmp = sta[x]; + for(int i = x;i > 1;i--)sta[i] = sta[i-1]; + sta[1] = tmp; + printf("Operation #%d: success.\n",index); +} +void gao5(){ + if(cnt == 0){ + printf("Operation #%d: empty.\n",index); + return; + } + int id = 1; + for(int i = 1;i <= cnt;i++) + if(sta[i] > sta[id]) + id = i; + gao4(id); +} +void gao6(int u){ + for(int i = 1;i <= cnt;i++) + if(sta[i] == u){ + gao4(i); + return; + } + printf("Operation #%d: invalid priority.\n",index); +} +void gao7(int u){ + for(int i = 1;i <= cnt;i++) + if(sta[i] == u){ + top = u; + printf("Operation #%d: success.\n",index); + return; + } + printf("Operation #%d: invalid priority.\n",index); +} +void gao8(){ + if(top != -1){ + top = -1; + printf("Operation #%d: success.\n",index); + } + else printf("Operation #%d: no such person.\n",index); +} +int main() +{ + int T; + int n; + scanf("%d",&T); + while(T--){ + scanf("%d",&n); + cnt = 0; + top = -1; + mp.clear(); + char op[20]; + int u; + for(index = 1;index <= n;index++){ + scanf("%s",op); + if(strcmp(op,"Add") == 0){ + scanf("%d",&u); + gao1(u); + } + else if(strcmp(op,"Close") == 0){ + scanf("%d",&u); + gao2(u); + } + else if(strcmp(op,"Chat") == 0){ + scanf("%d",&u); + gao3(u); + } + else if(strcmp(op,"Rotate") == 0){ + scanf("%d",&u); + gao4(u); + } + else if(strcmp(op,"Prior") == 0){ + gao5(); + } + else if(strcmp(op,"Choose") == 0){ + scanf("%d",&u); + gao6(u); + } + else if(strcmp(op,"Top") == 0){ + scanf("%d",&u); + gao7(u); + } + else gao8(); + } + if(top != -1 && mp[top]) + printf("Bye %d: %I64d\n",top,mp[top]); + for(int i = 1;i <= cnt;i++) + if(sta[i] != top && mp[sta[i]]) + printf("Bye %d: %I64d\n",sta[i],mp[sta[i]]); + } + return 0; +} diff --git a/HDOJ/5072_autoAC.cpp b/HDOJ/5072_autoAC.cpp new file mode 100644 index 0000000..df1e5f3 --- /dev/null +++ b/HDOJ/5072_autoAC.cpp @@ -0,0 +1,95 @@ +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +using namespace std; +const int MAXN = 100000; +int prime[MAXN+1]; +void getPrime(){ + memset(prime,0,sizeof(prime)); + for(int i = 2;i <= MAXN;i++){ + if(!prime[i])prime[++prime[0]] = i; + for(int j = 1;j <= prime[0] && prime[j] <= MAXN/i;j++){ + prime[prime[j]*i] = 1; + if(i%prime[j] == 0)break; + } + } +} +int factor[100][2]; +int fatCnt; +inline int getFactor(int x){ + fatCnt = 0; + for(int i = 1;prime[i] <= x/prime[i];i++) + if(x%prime[i] == 0){ + factor[fatCnt][0] = prime[i]; + factor[fatCnt][1] = 0; + while(x%prime[i] == 0){ + factor[fatCnt][1]++; + x /= prime[i]; + } + fatCnt++; + } + if(x != 1){ + factor[fatCnt][0] = x; + factor[fatCnt++][1] = 1; + } + return fatCnt; +} +int a[100010]; +int num[100010]; +int two[20]; +int main() +{ + int T; + int n; + scanf("%d",&T); + two[0] = 1; + for(int i = 1;i < 20;i++) + two[i] = two[i-1]<<1; + getPrime(); + while(T--){ + scanf("%d",&n); + memset(num,0,sizeof(num)); + for(int i = 0;i < n;i++){ + scanf("%d",&a[i]); + getFactor(a[i]); + for(int j = 0;j < two[fatCnt];j++){ + int tmp = 1; + for(int k = 0;k < fatCnt;k++) + if(j&two[k]){ + tmp *= factor[k][0]; + } + num[tmp]++; + } + } + long long ret = 0; + for(int i = 0;i < n;i++){ + getFactor(a[i]); + int cc = 0; + for(int j = 0;j < two[fatCnt];j++){ + int tmp = 1; + int cnt = 0; + for(int k = 0;k < fatCnt;k++) + if(j&two[k]){ + cnt++; + tmp *= factor[k][0]; + } + if(cnt&1)cc -= num[tmp]; + else cc += num[tmp]; + } + if(a[i] == 1)cc--; + ret += (long long)cc*(n-1-cc); + } + long long tot = (long long)n*(n-1)*(n-2)/6; + printf("%I64d\n",tot-ret/2); + } + return 0; +} diff --git a/HDOJ/5073_autoAC.cpp b/HDOJ/5073_autoAC.cpp new file mode 100644 index 0000000..8ebe6cd --- /dev/null +++ b/HDOJ/5073_autoAC.cpp @@ -0,0 +1,47 @@ +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +using namespace std; +double x[50010]; +int main() +{ + int T; + int n,k; + scanf("%d",&T); + while(T--){ + scanf("%d%d",&n,&k); + for(int i = 0;i < n;i++) + scanf("%lf",&x[i]); + sort(x,x+n); + if(n == k){ + printf("0\n"); + continue; + } + int cnt = n-k; + double sum = 0; + double sum2 = 0; + for(int i = 0;i < cnt;i++){ + sum += x[i]; + sum2 += x[i]*x[i]; + } + double ans = sum2 - 2*sum*(sum/cnt) + cnt*(sum/cnt)*(sum/cnt); + for(int i = cnt;i < n;i++){ + sum += x[i]; + sum2 += x[i]*x[i]; + sum -= x[i-cnt]; + sum2 -= x[i-cnt]*x[i-cnt]; + ans = min(ans,sum2-2*sum*(sum/cnt)+cnt*(sum/cnt)*(sum/cnt)); + } + printf("%.10lf\n",ans); + } + return 0; +} diff --git a/HDOJ/5074_autoAC.cpp b/HDOJ/5074_autoAC.cpp new file mode 100644 index 0000000..d1d21b4 --- /dev/null +++ b/HDOJ/5074_autoAC.cpp @@ -0,0 +1,48 @@ +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +using namespace std; +int a[100][100]; +int dp[110][55]; +int b[110]; +int main() +{ + int T; + int n,m; + scanf("%d",&T); + while(T--){ + scanf("%d%d",&n,&m); + for(int i = 1;i <= m;i++) + for(int j = 1;j <= m;j++) + scanf("%d",&a[i][j]); + memset(dp,-1,sizeof(dp)); + for(int i = 1;i <= n;i++)scanf("%d",&b[i]); + for(int i = 1;i <= m;i++) + dp[1][i] = 0; + int ans = -1; + for(int i = 1;i <= n;i++){ + for(int j = 1;j <= m;j++){ + if(b[i] > 0 && j != b[i]) + dp[i][j] = -1; + if(dp[i][j] == -1)continue; + if(i == n){ + ans = max(ans,dp[i][j]); + continue; + } + for(int k = 1;k <= m;k++) + dp[i+1][k] = max(dp[i+1][k],dp[i][j]+a[j][k]); + } + } + printf("%d\n",ans); + } + return 0; +} diff --git a/HDOJ/5076_autoAC.cpp b/HDOJ/5076_autoAC.cpp new file mode 100644 index 0000000..5003e1a --- /dev/null +++ b/HDOJ/5076_autoAC.cpp @@ -0,0 +1,155 @@ +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +using namespace std; +#define N 300 +#define inf 50000000 +int T, S, n, m, tot, cas, ans; +int head[N * 2], f[N], g[N], Less[N], Lid[N], More[N], Mid[N], dis[N * 2], qu[N + * 2]; +struct edge { + int v, w, next; +} ed[N * N * 100]; +int cut(int x) { + int i; + for (i = 0; x; x -= (x & (-x)), i++) + ; + return i; +} +void add(int u, int v, int w) { + ed[tot].v = v; + ed[tot].w = w; + ed[tot].next = head[u]; + head[u] = tot++; + ed[tot].v = u; + ed[tot].w = 0; + ed[tot].next = head[v]; + head[v] = tot++; +} +bool bfs() { + int l, r, u, v, i; + memset(dis, -1, sizeof(dis)); + dis[S] = 0; + qu[0] = S; + l = 0; + r = 1; + while (l < r) { + u = qu[l++]; + for (i = head[u]; ~i; i = ed[i].next) { + v = ed[i].v; + if (dis[v] < 0 && ed[i].w > 0) { + dis[v] = dis[u] + 1; + if (v == T) + return true; + qu[r++] = v; + } + } + } + return false; +} +int dfs(int u, int nowflow) { + if (u == T) + return nowflow; + int i, v, tmp, res = 0; + for (i = head[u]; ~i; i = ed[i].next) { + v = ed[i].v; + if (dis[v] == dis[u] + 1 && ed[i].w > 0) { + tmp = dfs(v, min(nowflow, ed[i].w)); + nowflow -= tmp; + ed[i].w -= tmp; + ed[i ^ 1].w += tmp; + res += tmp; + if (!nowflow) + break; + } + } + if (!nowflow) + dis[u] = -1; + return res; +} +int main() { + scanf("%d", &cas); + while (cas--) { + scanf("%d%d", &n, &m); + n = 1 << n; + m = 1 << m; + tot = 0; + memset(head, -1, sizeof(head)); + ans = 0; + memset(Less, -1, sizeof(Less)); + memset(More, -1, sizeof(More)); + S = 0; + T = n * 2 + 1; + for (int i = 0; i < n; i++) + scanf("%d", &f[i]); + for (int i = 0; i < n; i++) + scanf("%d", &g[i]); + for (int i = 0; i < n; i++) { + for (int j = 0; j < m; j++) { + int k; + scanf("%d", &k); + k += 1024; + if (j < f[i]) { + if (Less[i] < k) { + Less[i] = k; + Lid[i] = j; + } + } else { + if (More[i] < k) { + More[i] = k; + Mid[i] = j; + } + } + } + } + for (int i = 0; i < n; i++) { + int aa = cut(i); + if (aa & 1) { + add(S, i + 1, Less[i]); + add(i + 1 + n, T, More[i]); + } else { + add(S, i + 1, More[i]); + add(i + 1 + n, T, Less[i]); + } + add(i + 1, i + 1 + n, inf); + for (int j = i + 1; j < n; j++) { + if (cut(i ^ j) == 1) { + if (aa & 1) + add(i + 1, j + 1 + n, g[i] ^ g[j]); + else + add(j + 1, i + 1 + n, g[i] ^ g[j]); + } + } + } + while (bfs()) + ans += dfs(S, inf); + for (int i = 0; i < n; i++) { + if (i) + printf(" "); + int aa = cut(i); + if (aa & 1) { + if (dis[i + 1] != -1) + printf("%d", Lid[i]); + else + printf("%d", Mid[i]); + } else { + if (dis[i + 1] != -1) + printf("%d", Mid[i]); + else + printf("%d", Lid[i]); + } + } + printf("\n"); + } + return 0; +} diff --git a/HDOJ/5077_autoAC.cpp b/HDOJ/5077_autoAC.cpp new file mode 100644 index 0000000..e15f998 --- /dev/null +++ b/HDOJ/5077_autoAC.cpp @@ -0,0 +1,18 @@ +#include +#include +#include +using namespace std; +const int ans[300] = {1, 5, 6, 3, 6, 3, 7, 4, 7, 8, 4, 5, 4, 5, 4, 1, 6, 3, 7, 4, 7, 4, 9, 7, 8, 8, 7, 5, 7, 5, 7, 4, 7, 8, 4, 5, 8, 8, 7, 5, 8, 9, 5, 6, 8, 8, 5, 5, 4, 5, 4, 1, 7, 5, 7, 4, 8, 8, 5, 5, 5, 7, 6, 4, 7, 8, 8, 8, 4, 5, 7, 5, 8, 9, 8, 8, 5, 6, 5, 5, 4, 5, 7, 5, 4, 1, 7, 4, 8, 8, 5, 7, 5, 5, 6, 4, 8, 9, 8, 8, 8, 8, 5, 7, 11, 9, 8, 9, 8, 9, 8, 8, 5, 6, 5, 5, 5, 5, 6, 4, 8, 9, 8, 8, 8, 8, 8, 7, 8, 9, 9, 9, 9, 9, 10, 9, 5, 7, 6, 6, 6, 6, 7, 6, 9, 9, 10, 9, 10, 9, 10, 10, 7, 6, 7, 7, 7, 7, 9, 7, 5, 7, 6, 6, 7, 6, 7, 7, 5, 6, 2, 3, 6, 6, 4, 3, 6, 6, 7, 6, 7, 7, 9, 7, 6, 6, 4, 3, 7, 7, 7, 6, 5, 7, 7, 6, 6, 6, 7, 7, 5, 6, 6, 6, 2, 3, 4, 3, 6, 6, 7, 7, 7, 6, 9, 7, 6, 6, 7, 7, 4, 3, 7, 6, 5, 6, 6, 6, 6, 6, 7, 7, 8, 9, 5, 6, 5, 6, 2, 5, 2, 3, 4, 3, 4, 3, 7, 6, 5, 6, 2, 5, 2, 5, 4, 1}; +int main () { + int cas; + char p[10]; + scanf("%d", &cas); + while (cas--) { + scanf("%s", p); + int ret = 0; + for (int i = 0; i < 8; i++) + ret = ret * 2 + p[i] - '0'; + printf("%d\n", ans[ret]); + } + return 0; +} diff --git a/HDOJ/5078_autoAC.cpp b/HDOJ/5078_autoAC.cpp new file mode 100644 index 0000000..55b78ce --- /dev/null +++ b/HDOJ/5078_autoAC.cpp @@ -0,0 +1,37 @@ +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +using namespace std; +struct Node{ + double t,x,y; + void input(){ + scanf("%lf%lf%lf",&t,&x,&y); + } + double calc(Node b){ + return hypot(x-b.x,y-b.y)/(b.t-t); + } +}node[1010]; +int main() +{ + int T; + int n; + scanf("%d",&T); + while(T--){ + scanf("%d",&n); + for(int i = 0;i < n;i++)node[i].input(); + double ans = -1.0; + for(int i = 0;i < n-1;i++) + ans = max(ans,node[i].calc(node[i+1])); + printf("%.10lf\n",ans); + } + return 0; +} diff --git a/HDOJ/5079_autoAC.cpp b/HDOJ/5079_autoAC.cpp new file mode 100644 index 0000000..d18f841 --- /dev/null +++ b/HDOJ/5079_autoAC.cpp @@ -0,0 +1,164 @@ +#pragma comment(linker,"/STACK:102400000,102400000") +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +using namespace std; +#define X first +#define Y second +#define mp make_pair +#define pb push_back +#define mset(a) memset(a,0,sizeof(a)) +#define mmset(a) memset(a,-1,sizeof(a)) +#define mcpy(a,b) memcpy(a,b,sizeof(a)) +typedef double lf; +typedef long long ll; +typedef unsigned int uint; +typedef unsigned long long ull; +typedef pair pii; +typedef pair pll; +typedef pair pli; +typedef pair pdd; +typedef pair pip; +typedef pair ppi; +typedef pair ppp; +typedef vector vi; +typedef vector vpii; +const int inf=1000000007; +const ll linf=1000000000000000000LL; +const ull ulinf=(1ULL<<63)-10ULL; +const lf eps=0.000000001; +const lf pi=3.14159265358979323846; +template T abs(T a){return a>=0?a:-a;} +template int sign(T a){return a>eps?1:a<-eps?-1:0;} +template T sqr(T a){return a*a;} +template T gcd(T a,T b){return b?gcd(b,a%b):a;} +template T mod(T a,T b){T ret=a%b;if(ret<0)ret+=b;return ret;} +template T lowbit(T x){return x&-x;} +ll addmod(ll a,ll b,ll c){return ((a+b)%c+c)%c;} +ll mulmod(ll a,ll b,ll c){if(b==0LL)return 0LL;ll ret=mulmod(a,b>>1,c);ret=(ret+ret)%c;if(b&1LL)ret=(ret+a)%c;return ret;} +ll powmod(ll a,ll b,ll c){if(b==0LL)return 1LL;ll ret=powmod(a,b>>1,c);ret=ret*ret%c;if(b&1LL)ret=ret*a%c;return ret;} +ll modinv(ll a,ll b){return powmod(a,b-2LL,b);} +template void maxe(T &a,T b){if(a void mine(T &a,T b){if(a>b)a=b;} +int iszero(lf a){return a<=eps&&a>=-eps;} +template void geti(T &a){a=0;T b=1;char c=getchar();if(c=='-')b=-1;else a=c-48;while((c=getchar())!=' '&&c!='\n')a=a*10+c-48;a*=b;} +#define DEBUG(X) +const int N=11; +const int M=111111; +const int K=33; +const ll md=inf; +int test; +int n,m,k,ans; +int cnt; +char s[N]; +int a[N]; +int flag[N]; +int dp[N][M]; +int powsz[N]; +int aa[N]; +int main() +{ + scanf("%d",&test); + for(int tc=1;tc<=test;tc++) + { + scanf("%d",&n); + m=1; + for(int i=1;i<=n;i++) + { + scanf("%s",s); + a[i]=0; + for(int j=0;j=j&&bit +#include +#include +#include +#include +#include +#include +#include +#include +#include +#define ll long long +#define db double +#define PB push_back +#define lson k<<1 +#define rson k<<1|1 +using namespace std; +const int N = 55; +const db eps = 1e-8; +const db PI = acos(-1.0); +const ll MOD = 1000000007; +int n,m,mp[N][N]; +bool mk[N]; +ll c; +int sgn(db t) +{ + return t<-eps?-1:t>eps; +} +ll inv(ll t) +{ + ll res=1,k=MOD-2; + while(k) + { + if(k&1) res=(res*t)%MOD; + t=(t*t)%MOD; + k>>=1; + } + return res; +} +struct E +{ + int a,b; + void input() + { + scanf("%d%d",&a,&b); + } +} ed[N*N]; +struct P +{ + db x,y; + int id; + void input() + { + int _x,_y; + scanf("%d%d",&_x,&_y); + x=_x,y=_y; + } + P(db _x=0,db _y=0):x(_x),y(_y){} + P rot(db thta) + { + return P(x*cos(thta)-y*sin(thta), + x*sin(thta)+y*cos(thta)); + } + P rotByP(P center,db thta) + { + P tmp(x-center.x,y-center.y); + P ans=tmp.rot(thta); + ans=ans+center; + return ans; + } + P operator + (const P &t) const + { + return P(x+t.x,y+t.y); + } + bool operator == (const P &t) const + { + return sgn(x-t.x)==0&&sgn(y-t.y)==0; + } +}p[N],pb,np[N]; +int pt[N]; +ll g,ans; +bool check() +{ + for(int i=0;i +#include +#include +#include +using namespace std; +char ans[500], s[500]; +char pattern[] = "_small_"; +int main ( ) +{ + while ( ~scanf ( "%s" , s ) ) + { + int i = 0; + while ( s[i] ) + if ( s[i++] == '_' ) break; + int j = 0; + while ( s[i] ) + ans[j++] = s[i++]; + i = 0; + while ( pattern[i] ) + ans[j++] = pattern[i++]; + i = 0; + scanf ( "%s" , s); + while ( s[i] ) + if ( s[i++] == '_' ) break; + while ( s[i] ) + ans[j++] = s[i++]; + ans[j] = 0; + printf ( "%s\n" , ans ); + } +} diff --git a/HDOJ/5083_autoAC.cpp b/HDOJ/5083_autoAC.cpp new file mode 100644 index 0000000..6ddf036 --- /dev/null +++ b/HDOJ/5083_autoAC.cpp @@ -0,0 +1,159 @@ +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#pragma comment (linker,"/STACK:102400000,102400000") +#define maxn 1005 +#define MAXN 2005 +#define mod 1000000009 +#define INF 0x3f3f3f3f +#define pi acos(-1.0) +#define eps 1e-6 +typedef long long ll; +using namespace std; +char ope[6][5]={{"ADD"},{"SUB"},{"DIV"},{"MUL"},{"MOVE"},{"SET"}}; +char code[6][7]={{"000001"},{"000010"},{"000011"},{"000100"},{"000101"},{"000110"}}; +char co[31][6]={ {"00001"} , {"00010"} , {"00011"} , {"00100"} , {"00101"} , {"00110"} , {"00111"} , {"01000"} , {"01001"} , {"01010"} + , {"01011"} , {"01100"} , {"01101"} , {"01110"} , {"01111"} , {"10000"} , {"10001"} , {"10010"} , {"10011"} , {"10100"} + , {"10101"} , {"10110"} , {"10111"} , {"11000"} , {"11001"} , {"11010"} , {"11011"} , {"11100"} , {"11101"} , {"11110"} + , {"11111"}}; +char s1[5],s2[10]; +int OP(char str[]) +{ + for (int i=0;i<6;i++) + { + if (strcmp(str,ope[i])==0) + return i; + } +} +int main() +{ + int n; + while (~scanf("%d",&n)) + { + if (n==1) + { + scanf("%s%s",s1,s2); + int x=OP(s1); + int dd=x; + printf("%s",code[x]); + x=s2[1]-'0'; + int ok=0; + if (isdigit(s2[2])) + { + ok=1; + x=x*10; + x=x+s2[2]-'0'; + } + x--; + printf("%s",co[x]); + if (dd==5) + { + printf("00000\n"); + continue; + } + if (ok) + { + x=s2[5]-'0'; + if (isdigit(s2[6])) + { + x=x*10; + x=x+s2[6]-'0'; + } + } + else + { + x=s2[4]-'0'; + if (isdigit(s2[5])) + { + x=x*10; + x=x+s2[5]-'0'; + } + } + x--; + printf("%s\n",co[x]); + } + else if (n==0) + { + scanf("%s",s1); + int len=strlen(s1); + int t=1; + int sum=0; + for (int i=5;i>=0;i--) + { + int x=s1[i]-'0'; + sum+=t*x; + t=t*2; + } + if (sum>6||sum==0) + { + printf("Error!\n"); + continue; + } + sum--; + int o=sum; + int flag=sum; + t=1; + sum=0; + for (int i=10;i>=6;i--) + { + int x=s1[i]-'0'; + sum+=t*x; + t=t*2; + } + if (sum>31||sum==0) + { + printf("Error!\n"); + continue; + } + int aa=sum; + if (flag==5) + { + t=1; + sum=0; + for (int i=15;i>=11;i--) + { + int x=s1[i]-'0'; + sum+=t*x; + t=t*2; + } + if (sum==0) + { + printf("%s",ope[o]); + printf(" R%d",aa); + printf("\n"); + continue; + } + else + { + printf("Error!\n"); + continue; + } + } + t=1; + sum=0; + for (int i=15;i>=11;i--) + { + int x=s1[i]-'0'; + sum+=t*x; + t=t*2; + } + if (sum>31||sum==0) + { + printf("Error!\n"); + continue; + } + printf("%s",ope[o]); + printf(" R%d",aa); + printf(",R%d\n",sum); + } + } + return 0; +} diff --git a/HDOJ/5084_autoAC.cpp b/HDOJ/5084_autoAC.cpp new file mode 100644 index 0000000..a6c22a1 --- /dev/null +++ b/HDOJ/5084_autoAC.cpp @@ -0,0 +1,46 @@ +#include +#include +#include +#include +using namespace std; +__int64 dp[2200][2200]; +__int64 num[2200]; +bool mark[2200][2200]; +int N, Q; +int main(){ + while( scanf( "%d", &N ) != EOF ){ + for( int i = 0; i <= 2 * N - 2; i++ ){ + scanf( "%I64d", &num[i] ); + } + memset( mark, false, sizeof( mark ) ); + for( int i = 0; i <= N - 1; i++ ){ + for( int j = 2 * N - 2; j >= N - 1; j-- ){ + if( mark[i][j] ) continue; + __int64 sum = 0; + int t1 = i, t2 = j, t3 = N; + while( t3-- ){ + sum += num[t1++] * num[t2--]; + } + dp[i][j] = sum; + mark[i][j] = true; + t1 = i + 1, t2 = j - 1; + while( t1 <= N - 1 && t2 >= N - 1 ){ + sum = sum - num[t1-1] * num[t2+1] + num[t1+N-1] * num[t2-N+1]; + dp[t1][t2] = sum; + mark[t1][t2] = true; + t1++, t2--; + } + } + } + scanf( "%d", &Q ); + __int64 ans = 0, ans1 = 0; + int r, c; + while( Q-- ){ + scanf( "%d%d", &r, &c ); + ans1 = dp[N-1-(r+ans1)%N][N-1+(c+ans1)%N]; + ans += ans1; + } + printf( "%I64d\n", ans ); + } + return 0; +} diff --git a/HDOJ/5086_autoAC.cpp b/HDOJ/5086_autoAC.cpp new file mode 100644 index 0000000..9bb4414 --- /dev/null +++ b/HDOJ/5086_autoAC.cpp @@ -0,0 +1,35 @@ +#include +#include +#include +#define MAX 10000007 +#define LL __int64 +using namespace std; +int n; +LL a[MAX]; +int main() +{ + LL t,m,i,j,sum,xx=1000000007; + scanf("%I64d",&t); + while(t--) + { + scanf("%I64d",&n); + for(j=1; j<=n; j++) + { + scanf("%I64d",&a[j]); + } + a[0] = 0; + for(j=1;j<=n;j++) + { + a[j] = a[j]*j+a[j-1]; + a[j] = a[j]%xx; + } + sum = 0; + for(j=1;j<=n;j++) + { + sum = sum+a[j]; + sum = sum%xx; + } + printf("%I64d\n",sum); + } + return 0; +} diff --git a/HDOJ/5087_autoAC.cpp b/HDOJ/5087_autoAC.cpp new file mode 100644 index 0000000..9613d01 --- /dev/null +++ b/HDOJ/5087_autoAC.cpp @@ -0,0 +1,35 @@ +#include +#include +using namespace std; +const int N = 1005; +int n, a[N]; +int d[N], c[N], cas, ans; +int main() +{ + scanf("%d", &cas); + while (cas--) + { + scanf("%d", &n); + int sum = ans = 0; + for (int i = 1; i <= n; ++i) + { + scanf("%d", &a[i]); + d[i] = 1, c[i] = 1; + for (int j = 1; j < i; ++j) + { + if (a[j] >= a[i]) continue; + if (d[j] + 1 > d[i]) + { + d[i] = d[j] + 1; + c[i] = c[j]; + } + else if (d[j] + 1 == d[i]) c[i] = 2; + } + if(d[i] > ans) ans = d[i]; + } + for (int i = 1; i <= n; ++i) + if (d[i] == ans) sum += c[i]; + printf("%d\n", sum > 1 ? ans : ans - 1); + } + return 0; +} diff --git a/HDOJ/5088_autoAC.cpp b/HDOJ/5088_autoAC.cpp new file mode 100644 index 0000000..ed91d86 --- /dev/null +++ b/HDOJ/5088_autoAC.cpp @@ -0,0 +1,64 @@ +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#define inf 0x3f3f3f3f +#define Inf 0x3FFFFFFFFFFFFFFFLL +#define eps 1e-6 +#define pi acos(-1.0) +using namespace std; +typedef long long ll; +const int maxn = 1000 + 10; +ll a[maxn]; +int main() +{ + int t; + scanf("%d",&t); + while(t--) + { + int n; + scanf("%d",&n); + for(int i = 0;i < n;++i) + scanf("%I64d",&a[i]); + if(n > 40) + { + puts("Yes"); + continue; + } + int x = 0; + for(ll i = 0;i < 40;++i) + { + int p = -1; + for(ll j = x;j < n;++j) + { + if((a[j]>>i) & 1) + { + p = j; + break; + } + } + if(p == -1) continue; + swap(a[x],a[p]); + for(int j = x + 1;j < n;++j) + if((a[j]>>i) & 1) + a[j] ^= a[x]; + x++; + } + int cnt = 0; + for(int i = 0;i < n;++i) + if(a[i]) cnt++; + if(cnt < n) + puts("Yes"); + else + puts("No"); + } + return 0; +} diff --git a/HDOJ/5089_autoAC.cpp b/HDOJ/5089_autoAC.cpp new file mode 100644 index 0000000..a2e2065 --- /dev/null +++ b/HDOJ/5089_autoAC.cpp @@ -0,0 +1,78 @@ +#include +#include +#include +#include +#include +#include +#include +#include +#include +using namespace std; +#define RD(x) scanf("%d",&x) +#define RD2(x,y) scanf("%d%d",&x,&y) +#define RD3(x,y,z) scanf("%d%d%d",&x,&y,&z) +#define clr0(x) memset(x,0,sizeof(x)) +#define clr1(x) memset(x,-1,sizeof(x)) +#define eps 1e-9 +const double pi = acos(-1.0); +typedef long long LL; +typedef unsigned long long ULL; +const int modo = 1e9 + 7; +const int INF = 0x3f3f3f3f; +const int inf = 0x3fffffff; +const LL _inf = 1e18; +const int maxn = 55,maxm = 1<<12; +int n,k; +bool vis[maxn]; +double p[maxn]; +int pos[maxn],s[maxn]; +int main() +{ + int _,_g;RD(_); + while(_--){ + RD2(n,k); + clr0(vis); + for(int i = 0;i < n;++i){ + RD(s[i]); + p[i] = ((double)s[i])/100.0; + } + double mx = 0; + for(int g = 0;g <= k;++g){//╁g涓k - g涓 + double _p,res = 0; + int cnt = 0; + for(int i = 0;i < g;++i) + pos[cnt++] = i; + for(int i = 1;i <= k - g;++i) + pos[cnt++] = n - i; + for(int i = 0;i < cnt;++i){ + _p = 1; + for(int j = 0;j < cnt;++j){ + if(j != i) + _p *= p[pos[j]]; + else + _p *= (1 - p[pos[j]]); + } + res += _p; + } + if(mx - res < eps){ + mx = res; + _g = g; + } + } + for(int i = 0;i < _g;++i) + vis[i] = 1; + for(int i = n - (k - _g);i < n;++i){ + for(int j = i;j >= 0;--j){ + if(vis[j] || s[j] > s[i]) + break; + _g = j; + } + vis[_g] = 1; + } + _g = 1; + for(int i = 0;i < n;++i) + if(vis[i]) + printf("%d%c",i+1," \n"[_g == k]),_g++; + } + return 0; +} diff --git a/HDOJ/5090_autoAC.cpp b/HDOJ/5090_autoAC.cpp new file mode 100644 index 0000000..d3201b0 --- /dev/null +++ b/HDOJ/5090_autoAC.cpp @@ -0,0 +1,64 @@ +#include +#include +#include +using namespace std; +const int maxn = 110 ; +bool con[maxn][maxn],vis[maxn]; +int match[maxn],n,k,x; +void initial() +{ + memset(con,0,sizeof(con)); + memset(match,-1,sizeof(match)); +} +void input() +{ + scanf("%d %d",&n,&k); + for(int i=1;i<=n;i++) + { + scanf("%d",&x); + while(x<=n) + { + con[x][i]=1; + x+=k; + } + } +} +bool dfs(int x) +{ + for(int i=1;i<=n;i++) + { + if(!vis[i] && con[x][i]) + { + vis[i]=1; + if(match[i]==-1 || dfs(match[i])) + { + match[i]=x; + return true; + } + } + } + return false; +} +void solve() +{ + int cnt=0; + for(int i=1;i<=n;i++) + { + memset(vis,0,sizeof(vis)); + if(dfs(i)) cnt++; + } + if(cnt==n) printf("Jerry\n"); + else printf("Tom\n"); +} +int main() +{ + int T; + scanf("%d",&T); + while(T--) + { + initial(); + input(); + solve(); + } + return 0; +} diff --git a/HDOJ/5091_autoAC.cpp b/HDOJ/5091_autoAC.cpp new file mode 100644 index 0000000..e6a4502 --- /dev/null +++ b/HDOJ/5091_autoAC.cpp @@ -0,0 +1,96 @@ +#include +#include +#include +#include +#include +#include +#define N 20000 +#define inf 0x7ffffff +#define eps 1e-9 +#define pi acos(-1.0) +using namespace std; +struct node +{ + int x,y,flag; +}s[2*N+5]; +bool cmp(node a,node b) +{ + if(a.x != b.x) return a.x < b.x; + return a.flag > b.flag; +} +struct tree +{ + int l,r,flag,maxx; +}tree[4*2*N]; +void build(int o,int l,int r) +{ + tree[o].l = l; + tree[o].r = r; + tree[o].maxx = tree[o].flag = 0; + if(l == r) return ; + int m = (l+r)/2; + build(2*o,l,m); + build(2*o+1,m+1,r); +} +void pushup(int o) +{ + tree[o].maxx = max(tree[2*o].maxx, tree[2*o+1].maxx ); +} +void pushdown(int o) +{ + if(tree[o].flag != 0) + { + tree[2*o].flag += tree[o].flag; + tree[2*o+1].flag += tree[o].flag; + tree[2*o].maxx += tree[o].flag; + tree[2*o+1].maxx += tree[o].flag; + tree[o].flag = 0; + } +} +void update(int o,int x,int y,int v) +{ + if(x <= tree[o].l && tree[o].r <= y) + { + tree[o].flag += v; + tree[o].maxx += v; + return; + } + pushdown(o); + int m = (tree[o].l + tree[o].r)/2; + if(x <= m) update(2*o,x,y,v); + if(y > m) update(2*o+1,x,y,v); + pushup(o); +} +int main() +{ + int n,w,h; + while(scanf("%d",&n)) + { + if(n < 0) break; + scanf("%d%d",&w,&h); + int i; + for(i = 0; i < n; i++) + { + int x,y; + scanf("%d%d",&x,&y); + x += N; + y += N; + s[2*i].x = x; + s[2*i].y = y; + s[2*i].flag = 1; + s[2*i+1].x = x+w; + s[2*i+1].y = y; + s[2*i+1].flag = -1; + } + sort(s,s+2*n,cmp); + build(1,1,2*N+1); + int ans = 0; + for(i = 0; i < 2*n; i++) + { + update(1,s[i].y, s[i].y+h ,s[i].flag); + ans = max(ans,tree[1].maxx); + } + printf("%d\n",ans); + } + return 0; +} diff --git a/HDOJ/5092_autoAC.cpp b/HDOJ/5092_autoAC.cpp new file mode 100644 index 0000000..3f0e995 --- /dev/null +++ b/HDOJ/5092_autoAC.cpp @@ -0,0 +1,55 @@ +#include "stdio.h" +#include "string.h" +int inf=0x3f3f3f3f; +struct node +{ + int x,y; +}dp[110][110]; +int main() +{ + int Case,ii,i,j,n,m,ans; + int a[110][110]; + scanf("%d",&Case); + for (ii=1;ii<=Case;ii++) + { + scanf("%d%d",&n,&m); + for (i=1;i<=n;i++) + for (j=1;j<=m;j++) + scanf("%d",&a[i][j]); + memset(dp,inf,sizeof(dp)); + for (i=1;i<=m;i++) + dp[n][i].x=a[n][i]; + for (i=n-1;i>=1;i--) + for (j=1;j<=m;j++) + { + dp[i][j].x=dp[i+1][j].x+a[i][j]; + dp[i][j].y=j; + if (j-1>=1 && dp[i+1][j-1].x+a[i][j] +#include +#include +#include +#include +using namespace std; +struct node{ + int s,t,nxt ; +}e[2500005] ; +int m,n,head[5005],cnt,match[5005],vis[5005] ; +int find(int s) +{ + for(int i=head[s] ;i!=-1 ;i=e[i].nxt) + { + int tt=e[i].t ; + if(!vis[tt]) + { + vis[tt]=1 ; + if(match[tt]==-1 || find(match[tt])) + { + match[tt]=s ; + return 1 ; + } + } + } + return 0 ; +} +int cr,cc; +int max_match() +{ + int ans=0 ; + memset(match,-1,sizeof(match)) ; + for(int i=1 ;i +#include +#include +using namespace std; +int n, m, p; +int door[51][51][4], map[51][51]; +bool vis[51][51][1<<10]; +int xl[4]={-1,1,0,0}; +int yl[4]={0,0,-1,1}; +int getd(int a, int b, int c, int d){ + if(a==c){ + if(b Q; + Q.push(Node(1,1,map[1][1],0)); + while(!Q.empty()){ + Node nd = Q.front(); Q.pop(); + if(vis[nd.x][nd.y][nd.st]) continue; + vis[nd.x][nd.y][nd.st] = 1; + for(int i=0; i<4; i++){ + int a = nd.x+xl[i]; + int b = nd.y+yl[i]; + if(a<1 || a>n || b<1 || b>m) continue; + if(!door[nd.x][nd.y][i]) continue; + int st = nd.st; + if(door[nd.x][nd.y][i]>0){ + int d = 1<<(door[nd.x][nd.y][i]-1); + if(!(st&d)) continue; + } + if(a==n && b==m) return nd.u+1; + st |= map[a][b]; + if(!vis[a][b][st]) Q.push(Node(a,b,st,nd.u+1)); + } + } + return -1; +} +int main(){ + while(~scanf("%d %d %d", &n, &m, &p)){ + memset(door, -1, sizeof(door)); + memset(map, 0, sizeof(map)); + memset(vis, 0, sizeof(vis)); + int k; + scanf("%d", &k); + int a, b, c, d, e; + while(k--){ + scanf("%d %d %d %d %d", &a, &b, &c, &d, &e); + door[a][b][getd(a,b,c,d)] = e; + door[c][d][getd(c,d,a,b)] = e; + } + scanf("%d", &k); + while(k--){ + scanf("%d %d %d", &a, &b, &c); + map[a][b] |= (1<<(c-1)); + } + printf("%d\n", solve()); + } + return 0; +} diff --git a/HDOJ/5095_autoAC.cpp b/HDOJ/5095_autoAC.cpp new file mode 100644 index 0000000..84da365 --- /dev/null +++ b/HDOJ/5095_autoAC.cpp @@ -0,0 +1,74 @@ +#include +#include +#include +#include +#include +#include +#include +#include +#include +using namespace std; +#define RD(x) scanf("%d",&x) +#define RD2(x,y) scanf("%d%d",&x,&y) +#define RD3(x,y,z) scanf("%d%d%d",&x,&y,&z) +#define clr0(x) memset(x,0,sizeof(x)) +#define clr1(x) memset(x,-1,sizeof(x)) +#define eps 1e-9 +const double pi = acos(-1.0); +typedef long long LL; +typedef unsigned long long ULL; +const int modo = 1e9 + 7; +const int INF = 0x3f3f3f3f; +const int inf = 0x3fffffff; +const LL _inf = 1e18; +const int maxn = 105,maxm = 10005; +int p[maxn],n,k; +char q[maxn] = {'p','q','r','u','v','w','x','y','z','\n'}; +char ch[maxn]; +void work() +{ + for(int i = 0;i < 10;++i){ + RD(p[i]); + } + int k = 0; + while(k < 10 && p[k] == 0)k++; + if(k == 10){ + puts("0"); + return ; + } + if(k == 9){ + printf("%d\n",p[9]); + return; + } + if(p[k] == 1) + printf("%c",q[k]); + else if(p[k] == -1) + printf("-%c",q[k]); + else + printf("%d%c",p[k],q[k]); + for(int i = k+1;i < 9;++i){ + if(p[i] > 1) + printf("+%d%c",p[i],q[i]); + else if(p[i] < -1) + printf("%d%c",p[i],q[i]); + else if(p[i] == 1) + printf("+%c",q[i]); + else if(p[i] == -1) + printf("-%c",q[i]); + } + if(p[9] == 0) + puts(""); + else if(p[9] > 0) + printf("+%d\n",p[9]); + else + printf("%d\n",p[9]); + return; +} +int main() +{ + int _;RD(_); + while(_--){ + work(); + } + return 0; +} diff --git a/HDOJ/5096_autoAC.cpp b/HDOJ/5096_autoAC.cpp new file mode 100644 index 0000000..eb56381 --- /dev/null +++ b/HDOJ/5096_autoAC.cpp @@ -0,0 +1,164 @@ +#include +#include +#include +#include +#include +using namespace std; +const int N = 100100; +const int M = 5000; +int n, m, sol_num, tot; +int arr[11][M]; +int cnt[N][11]; +int sum[11]; +bool solve[N][10]; +char s1[20], s2[20]; +int solved[N]; +int pen[N]; +int last[N]; +struct Team{ + int id, ac; + Team(){} + Team(int id, int ac):id(id),ac(ac){} + bool operator < (const Team &A)const{ + return ac0; x-=lowbit(x)) res += arr[sol][x]; + return res; +} +Team t[N]; +map > MP[11]; +set ST; +void init(){ + for(int i=1; i<=m; i++){ + MP[i].clear(); + } + ST.clear(); + for(int i=0; i57) c=getchar(); + while(c>=48 && c<=57){ + x = x*10+c-48; + c = getchar(); + } +} +inline void read(int &x){ + char c=getchar(); + x = c-'A'; +} +void submit(){ + int min, id, flag, pro; + in(min); + in(id); + read(pro); + in(flag); + if(min - last[id] < 5 || solve[id][pro]) return; + last[id] = min; + if(flag){ + printf("[%d][%c]\n", id, pro+'A'); + int sol = solved[id]; + int penlty = pen[id]; + if(sol){ + MP[sol][penlty].erase(t[id]); + add(sol, penlty, -1); + sum[sol]--; + } + else{ + sol_num++; + ST.erase(id); + } + sol++; + penlty += min + cnt[id][pro]*20; + solved[id]++; + pen[id] = penlty; + t[id].ac = ++tot; + MP[sol][penlty].insert(t[id]); + add(sol, penlty, 1); + solve[id][pro]=1; + sum[sol]++; + } + else{ + cnt[id][pro]++; + } +} +int R(){ + int id, res; + in(id); + if(solved[id]==0) return sol_num+1; + res = cal(solved[id], pen[id]-1)+1; + for(int i=solved[id]+1; i<=m; i++) res+=sum[i]; + return res; +} +int find(int sol, int rank){ + int low=0, top=M, mid; + int ans = M; + while(low<=top){ + mid = (low+top)>>1; + int res = cal(sol, mid); + if(res >= rank){ + ans = min(ans, mid); + top = mid-1; + } + else{ + low = mid+1; + } + } + int tmp = cal(sol, ans-1); + if(tmp + 1 != rank) return -1; + return MP[sol][ans].begin()->id; +} +int T(){ + int rank; + in(rank); + if(rank > n) return -1; + if(rank == sol_num+1) return *ST.begin(); + if(rank > sol_num) return -1; + int i, res = 0; + for(i=m; i>=0; i--){ + res += sum[i]; + if(res >= rank) break; + } + res -= sum[i]; + return find(i, rank - res); +} +int main(){ + while(~scanf("%d %d", &n, &m)){ + init(); + while(~scanf("%s", s1) && s1[0]!='C'){ + if(s1[0]=='S') submit(); + else if(s1[0]=='T') printf("%d\n", T()); + else printf("%d\n", R()); + } + scanf("%s", s1); + puts(""); + } + return 0; +} diff --git a/HDOJ/5097_autoAC.cpp b/HDOJ/5097_autoAC.cpp new file mode 100644 index 0000000..0451dda --- /dev/null +++ b/HDOJ/5097_autoAC.cpp @@ -0,0 +1,49 @@ +#include +#include +#include +const double alpha = 0.85; +const double eps = 1e-10; +const int N = 3010; +int n; +double mat[N][N], q[2][N]; +inline double sqr(double x){ + return x*x; +} +bool ok(){ + double s = 0.0; + for(int i=0; i +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +using namespace std; +#define lp (p << 1) +#define rp (p << 1|1) +#define getmid(l,r) (l + (r - l) / 2) +#define MP(a,b) make_pair(a,b) +typedef long long ll; +const int INF = 1 << 30; +const int maxn = 1010; +int n,m,cnt; +int din[maxn],dout[maxn],reb[maxn]; +int vis[maxn],first[maxn],nex[maxn * maxn],ver[maxn * maxn],ecnt; +string s,id1,id2; +char name[1500]; +map< string,int > mp; +queue q1,q2; +void Add_edge(int u,int v){ + nex[++ecnt] = first[u]; + ver[ecnt] = v; + first[u] = ecnt; +} +void Init(){ + memset(reb,0,sizeof(reb)); + memset(vis,0,sizeof(vis)); + memset(din,0,sizeof(din)); + memset(dout,0,sizeof(dout)); + memset(first,-1,sizeof(first)); + while(!q1.empty()) q1.pop(); + while(!q2.empty()) q2.pop(); + ecnt = cnt = 0; + mp.clear(); +} +int Topo_count(){ + for(int i = 1; i <= cnt; ++i) if(din[i] == 0){ + if(reb[i] == 0) q1.push(i); + else q2.push(i); + } + int res = 0; + while(!q1.empty() || !q2.empty()){ + if(q1.empty() && !q2.empty()){ + ++res; + while(!q2.empty()){ + int x = q2.front(); q2.pop(); + q1.push(x); + } + } + while(!q1.empty()){ + int x = q1.front(); q1.pop(); + vis[x] = 1; + for(int i = first[x]; i != -1; i = nex[i]){ + int v = ver[i]; + din[v]--; + if(din[v] == 0){ + if(!reb[v]) q1.push(v); + else q2.push(v); + } + } + } + } + return res; +} +int main(){ + int a,b,len,flag; + scanf("%d",&n); + getchar(); + getchar(); + for(int Case = 1; Case <= n; ++Case){ + Init(); + while(getline(cin,s) != NULL){ + if(s[0] == '\0') + break; + istringstream sin(s); + sin >> name; + flag = 0; + int len = strlen(name); + for(int i = 0; i < len; ++i) + if(name[i] == '*') flag = 1; + name[len - 1 - flag] = '\0'; + id1 = name; + if(mp.find(id1) == mp.end()) + mp[id1]= ++cnt; + reb[mp[id1]] = flag; + while(sin >> id2){ + if(mp.find(id2) == mp.end()) + mp[id2] = ++cnt; + Add_edge(mp[id2],mp[id1]); + dout[mp[id2]]++; + din[mp[id1]]++; + } + } + printf("Case %d: %d\n",Case,Topo_count()); + } + return 0; +} diff --git a/HDOJ/5099_autoAC.cpp b/HDOJ/5099_autoAC.cpp new file mode 100644 index 0000000..5456728 --- /dev/null +++ b/HDOJ/5099_autoAC.cpp @@ -0,0 +1,72 @@ +#include +#include +#include +#include +#include +#include +#include +#include +#include +using namespace std; +#define RD(x) scanf("%d",&x) +#define RD2(x,y) scanf("%d%d",&x,&y) +#define RD3(x,y,z) scanf("%d%d%d",&x,&y,&z) +#define clr0(x) memset(x,0,sizeof(x)) +#define clr1(x) memset(x,-1,sizeof(x)) +#define eps 1e-9 +const double pi = acos(-1.0); +typedef long long LL; +typedef unsigned long long ULL; +const int modo = 1e9 + 7; +const int INF = 0x3f3f3f3f; +const int inf = 0x3fffffff; +const LL _inf = 1e18; +const int maxn = 105,maxm = 10005; +int p[maxn],n,k,cas = 1; +char a[maxn],b[maxn]; +void work() +{ + scanf("%s%s",a,b); + int n = strlen(a),m = strlen(b); + printf("Case %d: ",cas++); + if(a[0] > b[0]) + printf("%c ",'>'); + else if(a[0] == b[0]) + printf("%c ",'='); + else + printf("%c ",'<'); + int _a = (a[3]-'0')*10 + a[4] - '0',_b = (b[3]-'0')*10 + b[4] - '0'; + char __a,__b; + if(n == 5) + __a = 'A'; + else + __a = a[5]; + if(m == 5) + __b = 'A'; + else + __b = b[5]; + if(a[1] != b[1]){ + if(a[2] < b[2] || (a[2] == b[2] && _a < _b)) + printf("%c\n",'<'); + else if(a[2] > b[2] || (a[2] == b[2] && _a > _b)) + printf("%c\n",'>'); + else + printf("%c\n",'='); + }else if(a[1] == b[1]){ + if(a[2] < b[2] || (a[2] == b[2] && _a < _b) || (a[2] == b[2] && _a == _b && __a < __b)) + printf("%c\n",'<'); + else if(a[2] > b[2] || (a[2] == b[2] && _a > _b) || (a[2] == b[2] && _a == _b && __a > __b)) + printf("%c\n",'>'); + else + printf("%c\n",'='); + } + return; +} +int main() +{ + int _;RD(_); + while(_--){ + work(); + } + return 0; +}