abc196 abcd
A - Difference Max
Given are integers a, b, c, and d.
We will choose integers x and y such that a≤x≤b and c≤y≤d. Find the maximum possible value of x−y here.按题意输出最大的x-y 值即可, max(x-y) = max(x)-min(y)=b-c
B - Round Down
输入一个数,输出这个数向下取整得到的整数(n < 1e100), 当成字符串 输出小数点前的所有字符即可
C - Doubled
输入一个数,问小于这个数的符合条件整数的个数,条件是能分成两个相同的字符串 比如 1313 123123,(n <= 1e12), 所以最大的数为 599999 599999,直接枚举就行 当字符串相加得到的整数值超过 n 就break
D - Hanjo
给你一个H*W的方格图 A个1*2的板砖 B个1*1的板砖, 问有多少种方式填满方格图
直接dfs就行 可以用二维数组表示格子是否已被覆盖 (0,0 ...... h-1,w-1) 也可以用一个数的二进制状态来表示, 比如说如果2这个格子已被覆盖的话 那对这个数进行 bit | (1<<2) 即可
(H*W<= 16)
0 1 2 3 4 5 ..... w-1
w w+1 ............ ........2w-1
2w ...........................3w-1
........................................
..... .........................h*w-1
#include <bits/stdc++.h> using namespace std; #define _for(i,a,b) for(int i = (a); i < (b); i++) #define _rep(i,a,b) for(int i = (a); i <= (b); i++) #define all(v) (v).begin(), (v).end() #define nl "\n" #define reunique(v) v.resize(std::unique(v.begin(), v.end()) - v.begin()) #define sz(v) ((int)(v).size()) //#define LOCAL typedef long double ld; typedef long long ll; typedef unsigned long long ull; #ifdef LOCAL //#include "pretty_print.h" #define dbg(...) cerr << "[" << #__VA_ARGS__ << "]: ", debug_out(__VA_ARGS__) #else #define dbg(...) 42 #endif template <typename T> T sqr(T x) { return x * x; } template <typename T> T abs(T x) { return x < 0? -x : x; } template <typename T> T gcd(T a, T b) { return b? gcd(b, a % b) : a; } template <typename T> bool chmin(T &x, const T& y) { if (x > y) { x = y; return true; } return false; } template <typename T> bool chmax(T &x, const T& y) { if (x < y) { x = y; return true; } return false; } auto random_address = [] { char *p = new char; delete p; return (uint64_t) p; }; mt19937 rng(chrono::steady_clock::now().time_since_epoch().count() * (random_address() | 1)); mt19937_64 rngll(chrono::steady_clock::now().time_since_epoch().count() * (random_address() | 1));
void taskA() { int a,b,c,d; cin >> a >> b >> c >> d; cout << b-c; return; }
void taskB() { string s; cin >> s; int n = s.size(); for(auto c:s) { if(c == '.') break; cout << c; } return; }
void taskC1() { int t; //cin >> t; t = 1; while(t--) { ll x1; cin >> x1; int ans = 0; const int N = 1e6+10; _for(i,0,N) { int x = 6; _for(j,0,7) if(pow(10,j) > i) { x = j; break;} if(1LL*i+1LL*i*pow(10,x) > x1) { ans = i-1; break; } } cout << ans; } return; } void taskC() { ll n; cin >> n; const int N = 1e6+10; _for(i,0,N) { if(stoll(to_string(i)+to_string(i)) > n) { cout << i-1; break; } } return; }
int H,W,A,B,ans1; int vis[20][20]; void dfs1(int x, int y, int a1, int b1) {// 0,0 .... 0,W-1 1,w.... H-1,W-1 if(a1 < 0 or b1 < 0) return; if(y == W) x++, y = 0;// 行尾换个行 if(x == H) return (void) ans1++;//代表从0,0 到 H-1,W-1 都满了 if(vis[x][y]) return dfs1(x, y+1, a1, b1); vis[x][y] = 1; dfs1(x, y+1, a1, b1-1); if(y+1 < W and !vis[x][y+1]) { vis[x][y+1] = 1; dfs1(x, y+1, a1-1, b1); vis[x][y+1] = 0; } if(x+1 < H and !vis[x+1][y]) { vis[x+1][y] = 1; dfs1(x, y+1, a1-1, b1); vis[x+1][y] = 0; } vis[x][y] = 0; return; } void dfs(int s, int bit, int a1, int b1) { if(s == H*W) return (void) ans1++; if(bit & (1<<s)) return dfs(s+1, bit, a1, b1);//已被占用 if(a1) { if(s%W < W-1) dfs(s+1, bit | (1<<s) | (1<<(s+1)), a1-1, b1);//不是行尾 if((s+W) < H*W) dfs(s+1, bit | (1<<s) | (1<<(s+W)), a1-1, b1);//下一行还存在 } if(b1) { dfs(s+1, bit | (1<<s), a1, b1-1); } return; } void taskD() { cin >> H >> W >> A >> B;//BF ans1 = 0; //dfs(0, 0, A, B); dfs1(0, 0, A, B); cout << ans1; return; }
int main() { //ios::sync_with_stdio(false), cin.tie(nullptr), cout.tie(nullptr); taskD(); //taskA(); #ifdef LOCAL //assert(freopen("i.txt", "r", stdin)); assert(freopen("o.txt", "w", stdout)); //freopen("i.txt", "r", stdin); freopen("o.txt", "w", stdout); cerr << "Time execute: " << clock() / (double)CLOCKS_PER_SEC << " sec" << endl; #endif return 0; }