[20181031][模擬賽]
阿新 • • 發佈:2018-10-31
T1
思路
乍一看上去似乎是個簽到題。然而分數低的可憐。以為小寫字母的ASCII碼會比100小,開個100的陣列足夠了。結果忘了'a'就已經是96了。涼涼
題目有一個坑點就是,如果知道了25個字母所對應的字母,那麼另外一個也是可以推出來的。
程式碼
#include<cstdio> #include<iostream> #include<cstring> using namespace std; typedef long long ll; const int N = 1010; int bz[233]; ll read(){ ll x = 0, f = 1; char c = getchar(); while(c < '0' || c > '9') { if(c == '-') f = -1; c = getchar(); } while(c >= '0' && c <= '9') { x = x * 10 + c - '0'; c = getchar(); } return x * f; } char a[N],b[N],c[N],ans[N]; int bz2[233]; int main() { freopen("enc.in","r",stdin); freopen("enc.out","w",stdout); scanf("%s",a+1); scanf("%s",b+1); int n = strlen(a + 1); for(int i = 1;i <= n;++i) { if((bz[(int)b[i]] && bz[(int)b[i]] != a[i])) { puts("ERROR"); return 0; } bz[(int)b[i]] = a[i]; } int js = 0; for(int i = 1;i <= n;++i) { if(bz2[bz[b[i]]] == 0) { js++; bz2[bz[b[i]]] = 1; } } if(js == 25) { int k = 0; for(int i = 'a';i <= 'z';++i) { if(!bz2[i]) { k = i; break; } } for(int i = 'a';i <= 'z';++i) { if(!bz[i]) bz[i] = k; } } scanf("%s",c+1); int len = strlen(c+1); for(int i = 1;i <= len;++i) { if(!bz[(int)c[i]]) { puts("ERROR"); return 0; } ans[i] = bz[(int)c[i]]; } printf("%s",ans+1); return 0; }
T2
思路
顯然每個數字都會與前邊比自己大的數連邊,一定不會與比自己小的數連邊。所以這個題其實就是一個裸地最長上升子序列。
程式碼
#include<cstdio> #include<algorithm> #include<iostream> using namespace std; typedef long long ll; const int N = 100000 + 100; ll read(){ ll x = 0, f = 1; char c = getchar(); while(c < '0' || c > '9') { if(c == '-') f = -1; c = getchar(); } while(c >= '0' && c <= '9') { x = x * 10 + c - '0'; c = getchar(); } return x * f; } int a[N],ans,b[N],n; void solve() { for(int i = 1;i <= n;++i) { if(a[i] > b[ans]) b[++ans] = a[i]; else { int k = lower_bound(b+1,b+ans+1,a[i]) - b; b[k] = a[i]; } } } int main() { freopen("sort.in","r",stdin); freopen("sort.out","w",stdout); n = read(); for(int i = 1;i <= n;++i) a[i] = read(); b[0] = -1; solve(); cout<<ans; return 0; }
T3
思路
一開始以為又是一道水題。很開心的寫了一個dfs交卷了。然後涼涼。後來仔細一思考發現自己的思路有太多bug了。因為感覺資料比較難造就沒對拍23333
程式碼
#include <cstdlib> #include <cstdio> #include <cstring> #include <cmath> const int MaxN = 5005; int n; int mat[MaxN][MaxN]; int cycle[MaxN], cyclelen; int stack[MaxN], stop, spos[MaxN], vis[MaxN]; bool dfs(int x) { vis[x] = 1, stack[stop++] = x, spos[x] = stop-1; for (int i = 0; i < n; ++i) { if (mat[x][i]) { if (vis[i] == 1) { cyclelen = stop - spos[i]; memcpy(cycle, stack + spos[i], sizeof(int) * cyclelen); return true; } else if (vis[i] == 0) { bool v = dfs(i); if (v) return true; } } } --stop, vis[x] = 2; return false; } void gen(void) { int m = cyclelen; for (int i = 1; i < m-1; ++i) { // check 1 i i+1 if (mat[cycle[i+1]][cycle[0]]) { printf("%d %d %d\n", cycle[0]+1, cycle[i]+1, cycle[i+1]+1); } } } char tmp[MaxN]; int main(void) { freopen("game.in","r",stdin); freopen("game.out","w",stdout); scanf("%d", &n); for (int i = 0; i < n; ++i) { scanf("\n%s", tmp); for (int j = 0; j < n; ++j) { mat[i][j] = tmp[j] == '1'; } } for (int i = 0; i < n; ++i) { if (vis[i] == 0) { bool found = dfs(i); if (found) { gen(); return 0; } } } printf("-1\n"); fclose(stdin); fclose(stdout); return 0; }