//轨道炮
cpp
#include<iostream>
using namespace std;
#include<algorithm>
int logs[100010];
int main()
{
int n;
cin >> n;
for (int i = 1;i <= n;i++)
{
cin >> logs[i];
}
sort(logs + 1, logs + n + 1);
int ans = 1000000000;
for (int i = 2;i <= n;i++)
{
if (logs[i] - logs[i - 1] < ans)ans = logs[i] - logs[i - 1];
}
int flag = 0;
int res = 1;
while (flag==0)
{
res = 1;
for (int i = 2;i <= n;i++)
{
if ((logs[i] - logs[i - 1]) % ans == 0)
{
res += ((logs[i] - logs[i - 1]) / ans);
}
else
{
ans--;
break;
}
}
flag = 1;
}
cout << res << endl;
return 0;
}
cpp
#include<iostream>
using namespace std;
#include<string>
int arr[30];
int main()
{
string str;
cin >> str;
for (int i = 0;i < str.length();i++)
{
arr[int(str[i]) - 96]+=1;
}
int ans1=0;
int ans2;
for (int i = 1;i <= 26;i++)
{
if (arr[i] > ans1)
{
ans2 = i;
ans1 = arr[i];
}
}
//cout << arr[15] << endl;
cout << char(ans2 + 96) << endl << ans1 << endl;
return 0;
}
//怒砍20分
cpp
#include<iostream>
using namespace std;
char ch[30][30];
char chs[30][30];
int dx[] = { -1,1,0,0 };
int dy[] = { 0,0,-1,1 };
int n, m;
void dfs(int x, int y)
{
chs[x][y] = '1';
ch[x][y] = '0';
for (int i = 0;i < 4;i++)
{
if (x + dx[i] >= 1 && y + dy[i] >= 1&& x + dx[i]<=n&& y + dy[i]<=m)
{
if (ch[x + dx[i]][y + dy[i]] == '1')
{
dfs(x + dx[i], y + dy[i]);
}
}
}
}
int daan()
{
int ans1 = 0;
int ans2 = 0;
for (int i = 1;i <= n;i++)
{
for (int j = 1;j <= m;j++)
{
if (chs[i][j] == '1')
{
if (i == 1 && j == 1)ans1++;
else if (i == 1)
{
if (chs[i][j - 1] == '0')ans1++;
}
else if (j == 1)
{
if (chs[i - 1][j] == '0')ans1++;
}
else if (chs[i - 1][j] == '0' && chs[i][j - 1] == '0')ans1++;
}
}
}
for (int i = 1;i < n;i++)
{
if (chs[i + 1][m] == '0'&&chs[i][m]=='1')ans2++;
}
for (int i = 1;i < m;i++)
{
if (chs[n][i+1] == '0' && chs[n][i] == '1')ans2++;
}
if (chs[n][m] == '1')ans2++;
//cout << "ans1=" << ans1 << " " << "ans2=" << ans2 << endl;
return max(ans1, ans2);
}
int main()
{
int ans = 0;
cin >> n >> m;
for (int i = 1;i <= n;i++)
{
for (int j = 1;j <= m;j++)
{
cin >> ch[i][j];
}
}
for (int i = 1;i <= n;i++)
{
for (int j = 1;j <= m;j++)
{
if (ch[i][j]=='1')
{
for (int z = 1;z <= n;z++)
{
for (int w = 1;w <= m;w++)
{
chs[z][w] = '0';
}
}
dfs(i, j);
/*for (int z = 1;z <= n;z++)
{
for (int w = 1;w <= m;w++)
{
cout << chs[z][w];
}
cout << endl;
}*/
ans += daan();
}
}
}
cout << ans << endl;
return 0;
}
cpp
#include<iostream>
using namespace std;
#include<string>
int main()
{
string str;
cin >> str;
int l = str.length();
int ans = 0;
for (int i = 0;i < l;i++)
{
ans += (int(str[i] - 48));
}
int flag = ans;
while ((ans / 10) != 0)
{
flag = 0;
while (ans)
{
flag += (ans % 10);
ans /= 10;
}
ans = flag;
}
cout << flag << endl;
return 0;
}
cpp
#include<iostream>
using namespace std;
bool use[1000010];
int main()
{
int n, m;
cin >> n >> m;
int maxx = max(n, m);
int minn = min(n, m);
int ans = minn-1;
for (int i = 1;i <= n*m;i++)
{
if (i < minn)
{
use[i] = true;
ans = i;
}
else
{
if (i % minn == 0 || i % maxx == 0)use[i] = false;
else
{
if (i > maxx)
{
if (use[i - minn] == true && use[i - maxx] == true)
{
use[i] = true;
ans = i;
}
}
else if(use[i-minn])
{
use[i] = true;
ans = i;
}
}
}
}
cout << ans << endl;
return 0;
}
cpp
#include<iostream>
using namespace std;
int n, m;
int sum = 0;
bool use[15][15];
int arr[15][15];
int ans = 10000;
int dx[] = { 0 ,0,-1,1 };
int dy[] = { -1,1,0,0 };
void dfs(int x,int y,int num, int d)
{
//cout << num <<" "<< x<<" "<<y <<" "<< ans<< endl;
if (num > sum)return;
else if (num == sum)
{
if (d < ans)ans = d ;
return;
}
else if (d >= ans)return;
else
{
use[x][y] = true;
for (int i = 0;i < 4;i++)
{
if (x + dx[i] > 0 && x + dx[i] <= n && y + dy[i] > 0 && y + dy[i] <= m && use[x + dx[i]][y + dy[i]] == false)
{
dfs(x + dx[i], y + dy[i], num + arr[x+dx[i]][y+dy[i]], d + 1);
}
}
use[x][y] = false;
}
return;
}
int main()
{//43
cin >> m >> n;
for (int i = 1;i <= n;i++)
{
for (int j = 1;j <= m;j++)
{
cin >> arr[i][j];
sum += arr[i][j];
}
}
if (sum % 2 != 0)
{
cout << 0 << endl;
}
else
{
sum /= 2;
dfs(1, 1, arr[1][1], 1);
if (ans == 10000)
{
cout << 0 << endl;
}
else
{
cout << ans << endl;
}
}
return 0;
}
cpp
#include<iostream>
using namespace std;
#include<vector>
int n;
int ans = 0;
int arr[10];
bool use[10];
void f()
{
//cout << 1 << endl;
for (int i = 1;i <= 7;i++)
{
int flag1 = 1;
int num1 = 0;
while (flag1!=i+1)///1-5 1 12 123
{
num1 *= 10;
num1 += arr[flag1];
flag1++;
}
if (num1 >= n)break;
for (int j = i + 1;j <= 8;j++)
{
int num2 = 0;
int flag2 = i+1;
while (flag2!=j+1)
{
num2 *= 10;
num2 += arr[flag2];
flag2++;
}
int num3 = 0;
int flag3 = j+1;
while (flag3 != 10)
{
num3 *= 10;
num3 += arr[flag3];
flag3++;
}
long long n1 = n * num3;
long long n2 = num1 * num3 + num2;
if (n1 == n2)ans++;
}
}
}
void dfs(int u)
{
//cout << 2 << endl;
if (u == 10)
{
f();
return;
}
for (int i = 1;i <= 9;i++)
{
if (!use[i])
{
arr[u] = i;
use[i] = true;
dfs(u + 1);
use[i] = false;
}
}
}
int main()
{
cin >> n;
dfs(1);
cout << ans << endl;
return 0;
}
//#include<iostream>
//#include <algorithm>
//using namespace std;
//int arr[9] = { 1, 2, 3, 4, 5, 6, 7, 8, 9 };
//int get_num_helper(int a, int b)
//{
// int tmp = 0;
// while (a <= b)
// {
// tmp *= 10;
// tmp += arr[a];
// a++;
// }
// return tmp;
//}
//void get_num(int i, int j, int& a, int& b, int& c)
//{
// a = get_num_helper(0, i);
// b = get_num_helper(i + 1, j);
// c = get_num_helper(j + 1, 8);
//}
//int main()
//{
// int n;
// int ans = 0;
// cin >> n;
// // 1.给出1~9的所有排列9!
// do {
// // 2.对于每个排列进行划分:划分为整数a,分母b,分子c
// int a, b, c;
// for (int i = 0; i < 8; i++)
// {
// for (int j = i + 1; j < 9; j++)
// {
// get_num(i, j, a, b, c);
// if (a == 0 || b == 0 || c == 0) continue;
// // 3.检验划分后的结果是否等于给定数字n
// if (b % c == 0 && a + (b / c) == n) ans++;
// }
// }
//
// } while (next_permutation(arr, arr + 9));
//
// cout << ans << endl;
//
// return 0;
//}
cpp
#include<iostream>
using namespace std;
int main()
{
int a, b, c;
cin >> a >> b >> c;
int ans = a * b * c;
for (int i = a * b * c;i >= 1;i--)
{
if ( i % a == 0 && i % b == 0 && i % c == 0)
{
ans = i;
}
}
cout << ans << endl;
return 0;
}