Tournament ZOJ - 4063 (青岛区域赛 F 打表)

打表题。。

规律是找出来了 奈何优化不了 。。。。

#include <iostream>
#include <cstdio>
#include <sstream>
#include <cstring>
#include <map>
#include <cctype>
#include <set>
#include <vector>
#include <stack>
#include <queue>
#include <algorithm>
#include <cmath>
#include <bitset>
#define rap(i, a, n) for(int i=a; i<=n; i++)
#define rep(i, a, n) for(int i=a; i<n; i++)
#define lap(i, a, n) for(int i=n; i>=a; i--)
#define lep(i, a, n) for(int i=n; i>a; i--)
#define rd(a) scanf("%d", &a)
#define rlld(a) scanf("%lld", &a)
#define rc(a) scanf("%c", &a)
#define rs(a) scanf("%s", a)
#define rb(a) scanf("%lf", &a)
#define rf(a) scanf("%f", &a)
#define pd(a) printf("%d\n", a)
#define plld(a) printf("%lld\n", a)
#define pc(a) printf("%c\n", a)
#define ps(a) printf("%s\n", a)
#define MOD 2018
#define LL long long
#define ULL unsigned long long
#define Pair pair<int, int>
#define mem(a, b) memset(a, b, sizeof(a))
#define _ ios_base::sync_with_stdio(0),cin.tie(0)
//freopen("1.txt", "r", stdin);
using namespace std;
const int maxn = , INF = 0x7fffffff, LL_INF = 0x7fffffffffffffff;
int way[maxn][maxn];
int sta[maxn];
void solve()
{
way[][] = ;
for(int i = ; i <= ; i *= )
{
int k = i >> ;
for(int x = ; x <= k; x++)
for(int y = ; y <= k; y++)
{
way[x + k][y + k] = way[x][y];
way[x + k][y] = way[x][y + k] = way[x][y] + k;
}
}
} int main()
{
int T, n, k;
solve();
cin >> T;
while(T--)
{
int cnt = ;
cin >> n >> k;
// if((n & 1) || !(n & 1) && k > n - 1)
// {
// cout << "Impossible" << endl;
// continue;
// }
for (int i = ; i <= n; i++)
{
bool flag = ;
for (int j = ; j <= n; j++)
{
if(way[i][j] > n)
{
flag = ; break;
}
}
if(!flag) sta[cnt++] = i;
}
if(cnt < k)
{
cout << "Impossible" << endl;
continue;
}
for(int i = ; i < k; i++)
for(int j = ; j <= n; j++)
printf("%d%s", way[sta[i]][j], (j == n ? "\n" : " ")); } return ;
}
上一篇:jspsmart(支持中文下载)


下一篇:HashMap 的遍历key与value的方法