Jerry1973

804

hqxx_xxx
limie
maro

Jerry1973
2019-07-03 14:29
#include <algorithm>
#include <iostream>
using namespace std;
const int maxn = 15;
int d[maxn], f[maxn];
int main()
{
d[1] = 1, f[1] = 1;
for (int i = 2; i <= 12; i++)
d[i] = 1 + 2 * d[i - 1];
for (int n = 2; n <= 12; n++)
{
int ans = 0x3f3f3f3f;
for (int i = 1; i < n; i++)
ans = min(ans, 2 * f[i] + d[n - i]);
f[n] = ans;
}
for (int i = 1; i <= 12; i++)
cout << f[i] << endl;
return 0;
}


Jerry1973
2019-07-03 13:53
#include <algorithm>
#include <iostream>
using namespace std;
const int maxn = 7;
bool Map[maxn][maxn],now[maxn][maxn];
int ans , curans = 0;
int dir[5][2] = {{1, 0}, {-1, 0}, {0, 1}, {0, -1}, {0, 0}};
void turn(int x, int y)
{
for (int i = 0; i < 5; i++)
{
int nx = x + dir[i][0], ny = y + dir[i][1];
if (nx >= 0 && nx < 5 && ny >= 0 && ny < 5)
now[nx][ny] ^= 1;
}
}
int main()
{
int T;
cin >> T;
while (T--)
{
ans = 0x3f3f3f3f;
for (int i = 0; i < 5; i++)
for (int j = 0; j < 5; j++)
{
char tmp;
cin>>tmp;
if (tmp=='1') Map[i][j]=1;
if (tmp=='0') Map[i][j]=0;
}
for (int i = 0; i < 1 << 5; i++)
{
for (int k=0;k<5;k++)
for (int j=0;j<5;j++)
now[k][j]=Map[k][j];
for (int j = i, pos = 0; j; j >>= 1, pos++)
if (j & 1)
{
turn(0, pos);
curans++;
}
for (int j = 1; j < 5; j++)
for (int k = 0; k < 5; k++)
if (!now[j - 1][k])
{
turn(j, k);
curans++;
}
bool flag = 1;
for (int j = 0; j < 5; j++)
if (!now[4][j])
flag = 0;
if (flag)
ans = min(ans, curans);
curans = 0;
}
if (ans > 6)
cout << -1 << endl;
else
cout << ans << endl;
}
return 0;
}


Jerry1973
2019-07-03 10:09
#include <iostream>
#include <vector>
using namespace std;
vector<int> chose;
int n;
void dfs(int dep,int state)
{
if (dep==n)
{
for (auto i:chose)
cout<<i<<" ";
cout<<endl;
return;
}
for(int i=1;i<=n;i++)
{
if (state>>(i-1)&1) continue;
chose.push_back(i);
dfs(dep+1,state|1<<(i-1));
chose.pop_back();
}
}
int main()
{
cin>>n;
dfs(0,0);
return 0;
}


Jerry1973
2019-07-03 06:32
#include <iostream>
using namespace std;
int n,m;
void dfs(int dep,int state,int get)
{
if (get+n-dep<m) return;
if (get==m)
{
for (int i=1;state;state>>=1,i++)
if (state&1) cout<<i<<" ";
cout<<endl;
return;
}
dfs(dep+1,state|1<<dep,get+1);
dfs(dep+1,state,get);
}
int main()
{
cin>>n>>m;
dfs(0,0,0);
return 0;
}


Jerry1973
2019-07-03 03:31
#include <iostream>
using namespace std;
int n;
void dfs(int dep,int state)
{
if (dep==n)
{
for (int i=1;state;state>>=1,i++)
if (state&1) cout<<i<<" ";
cout<<endl;
return;
}
dfs(dep+1,state);
dfs(dep+1,state|1<<dep);
}
int main()
{
cin>>n;
dfs(0,0);
return 0;
}


Jerry1973
2019-07-01 13:33
#include <iostream>
using namespace std;
int main()
{
long long a, b, p;
cin >> a >> b >> p;
long long ans = 0;  //不同于a^b：这里不用先%p是因为就算p=1时ans也为0
for (; b; b >>= 1)
{
if (b & 1)
ans = (ans + a) % p;    //不同于a^b:这里不需要强制类型转换是因为1e8*2<2^63-1(即ans+a最大值在long long范围内)
a = a * 2 % p;
}
cout << ans << endl;
return 0;
}


Jerry1973
2019-06-27 15:16

#include <iostream>
using namespace std;
int main()
{
long long a, b, p, ans;
cin >> a >> b >> p;
ans = 1 % p;
do
{
if (b & 1)
{
ans *= a;
ans %= p;
}
a *= a;
a %= p;
} while (b >>= 1);
cout << ans << endl;
return 0;
}


#include <iostream>
using namespace std;
int main()
{
int a, b, p;
cin >> a >> b >> p;
int ans = 1 % p;    //为什么要先%一下呢？考虑b=0,p=0的情况。
for (; b; b >>= 1)
{
if (b & 1)
ans = (long long)ans * a % p;   //为什么不用*=呢？其实我挺想用，像上面：将变量们开成long long就可以了，只是不方便%p。
a = (long long)a * a % p;
}
cout << ans << endl;    //个人认为放在这里%也没有问题。
return 0;
}