1001 度度熊与数字
#pragma comment(linker, "/STACK:36777216")
#include <bits/stdc++.h>
#define REP(i,n) for(int i=0;i<int(n);++i)
#define FOR(i,a,b) for(int i=int(a);i<int(b);++i)
#define DWN(i,b,a) for(int i=int(b);i>=int(a);--i)
/// type define
typedef double DB;
typedef long long LL;
typedef std::vector<int>VI;
typedef std::vector<LL>VLL;
typedef std::pair<int, int>PII;
typedef std::pair<LL, LL>PLL;
typedef std::vector<PII >VPII;
/// const
static const double eps = 1e-8;
static const double pi = acos(-1.0);
static const int inf = 0x3f3f3f3f;
static const LL INF = 0x3f3f3f3f3f3f3f3f;
/// common statement
#define PB push_back
#define MP std::make_pair
#define fi first
#define se second
/****************************************************************/
const int maxn = 2e6 + 7;
const LL MOD = 1e9 + 7;
bool chk(LL x, LL n) {
int s = 0;
while(n) {
s += n % 10;
n /= 10;
}
return s % x == 0;
}
void solve() {
/*********** start your code here. ************/
LL n;
std::cin >> n;
VI ans;
for(LL x = 1; x * x <= n; ++x) {
if(n % x)
continue;
if(chk(x, n))
ans.PB(x);
if(chk(n / x, n) && x != n / x)
ans.PB(n / x);
}
std::cout << ans.size() << "
";
std::sort(ans.begin(),ans.end());
for(int i = 0, sz = ans.size(); i < sz; ++i)
std::cout << ans[i] << (i == sz - 1 ? "
" : " ");
}
void init() {
}
int main() {
//std::ios::sync_with_stdio(false);
//std::cin.tie(0);
//init();
int T;
std::cin >> T;
while(T--)
solve();
return 0;
}
1002 度度熊与排列
#pragma comment(linker, "/STACK:36777216")
#include <bits/stdc++.h>
#define REP(i,n) for(int i=0;i<int(n);++i)
#define FOR(i,a,b) for(int i=int(a);i<int(b);++i)
#define DWN(i,b,a) for(int i=int(b);i>=int(a);--i)
/// type define
typedef double DB;
typedef long long LL;
typedef std::vector<int>VI;
typedef std::vector<LL>VLL;
typedef std::pair<int, int>PII;
typedef std::pair<LL, LL>PLL;
typedef std::vector<PII >VPII;
/// const
static const double eps = 1e-8;
static const double pi = acos(-1.0);
static const int inf = 0x3f3f3f3f;
static const LL INF = 0x3f3f3f3f3f3f3f3f;
/// common statement
#define PB push_back
#define MP std::make_pair
#define fi first
#define se second
/****************************************************************/
const int maxn = 1e3 + 7;
const LL MOD = 1e9 + 7;
int mat[maxn][maxn];
void parse(std::string is, std::string os) {
int sz = is.length();
REP(i, sz)REP(j, sz)if(is[i] == os[j])
mat[i][j]++;
}
std::vector<int>edges[maxn];
bool vis[maxn];
int boy[maxn];
int gril[maxn];
bool dfs(int v) {
int len = edges[v].size();
for(int i = 0; i < len; i++) {
int end = edges[v][i];
if(!vis[end]) {
vis[end] = 1;
if(boy[end] == 0 || dfs(boy[end])) {
boy[end] = v;
gril[v] = end;
return 1;
}
}
}
return 0;
}
void solve() {
/*********** start your code here. ************/
int n, m;
std::cin >> n >> m;
std::cin.get();
REP(i, maxn)REP(j, maxn) mat[i][j] = 0;
for(int i = 0; i < n; ++i) {
std::string is, os;
getline(std::cin, is);
getline(std::cin, os);
parse(is, os);
}
REP(i,m) edges[i].clear();
REP(i, m)REP(j, m) {
mat[i][j] = mat[i][j] == n ? n : 0;
if(mat[i][j])
edges[i].PB(j);
}
//REP(i,m) REP(j,m) std::cout << mat[i][j] << (j == m-1 ? "
" : " ");
int ans = 0;
memset(boy,0,sizeof(boy));
for(int i = m - 1; i >= 0; i--) {
memset(vis, 0, sizeof(vis));
if(dfs(i)) {
ans++;
}
}
if(ans != m) {
std::cout << "-1
";
} else {
REP(i,m)std::cout << gril[i]+1 << (i == m-1 ? "
" : " ");
}
}
void init() {
}
int main() {
//std::ios::sync_with_stdio(false);
//std::cin.tie(0);
//init();
int T;
std::cin >> T;
while(T--)
solve();
return 0;
}
1003 度度熊与运算式 1
#pragma comment(linker, "/STACK:36777216")
#include <bits/stdc++.h>
#define REP(i,n) for(int i=0;i<int(n);++i)
#define FOR(i,a,b) for(int i=int(a);i<int(b);++i)
#define DWN(i,b,a) for(int i=int(b);i>=int(a);--i)
/// type define
typedef double DB;
typedef long long LL;
typedef std::vector<int>VI;
typedef std::vector<LL>VLL;
typedef std::pair<int, int>PII;
typedef std::pair<LL, LL>PLL;
typedef std::vector<PII >VPII;
/// const
static const double eps = 1e-8;
static const double pi = acos(-1.0);
static const int inf = 0x3f3f3f3f;
static const LL INF = 0x3f3f3f3f3f3f3f3f;
/// common statement
#define PB push_back
#define MP std::make_pair
#define fi first
#define se second
/****************************************************************/
const int maxn = 1e6 + 7;
const LL MOD = 1e9 + 7;
VI ans(maxn);
int cal(const char *str) {
int t, cur = 0;
ans.clear();
ans.PB(1);
for(int i = 0, sz = strlen(str); i < sz; i++) {
switch(str[i]) {
case '?':
ans[cur]++;
break;
case '^':
ans.PB(1);
cur++;
break;
}
}
int ret(0);
//for(auto i : ans) std::cout << i << " ";
//std::cout << "
";
int b[32] = {0};
memset(b, 0, sizeof(b));
for(auto i : ans) {
for(int j = 30; j > 0; --j)
if(i & (1 << j))
b[j]++;
}
for(int i = 30; i > 0; --i) {
if(b[i] ) {
b[i - 1] += (b[i] - 1)*2;
b[i] = 1, ret |= (1 << i);
}
}
ret |= ((strlen(str) + 1 & 1) ? 1 : 0);
return ret;
}
void solve() {
/*********** start your code here. ************/
std::string str, fs;
getline(std::cin, str);
std::cout << cal(str.c_str()) << "
";
}
void init() {
}
int main() {
std::ios::sync_with_stdio(false);
std::cin.tie(0);
//init();
int T;
std::cin >> T;
std::cin.get();
while(T--)
solve();
return 0;
}