# 2023.3.15 30天蓝桥训练打卡题目 day 12

szx233 2023-03-15 13:54:23

``````#include<iostream>
using namespace std;
typedef long long ll;

int main()
{
string s;
cin >> s;
int t = s.size(), p = 0;
for(int i = t - 1; i >= 0; i -- )
if(s[i] == '0') p ++ ;
else break;
cout << p;

return 0;
}
``````

``````#include<iostream>
using namespace std;
typedef long long ll;

bool is_prime(int x)
{
if(x == 1) return false;
for(int i = 2; i <= x / i; i ++ )
if(x % i == 0) return false;
return true;
}

int main()
{
int ma = 0;
for(int i = 2; i <= 400; i ++ )
{
if(is_prime(i))
{
string h = to_string(i);
bool flag = false;
for(int j = 1; j <= h.size(); j ++ )
for(int k = 0; k < h.size() - j + 1; k ++ )
if(!is_prime(stoi(h.substr(k, j))))
flag = true;
if(!flag) ma = max(ma, i);
}
}
cout << ma;

return 0;
}``````

``````#include<iostream>
#include<algorithm>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> PII;
const int N = 2e5 + 10;
PII a[N];
ll s[N];
bool cmp(PII x, PII y)
{
return x.first < y.first;
}
int main()
{
ll n, m, q = 0;
cin >> n >> m;
for(int i = 1; i <= n; i ++ ) cin >> a[i].first;
for(int i = 1; i <= n; i ++ ) cin >> a[i].second, q += a[i].second;
sort(a + 1, a + n + 1 ,cmp);
int k = 1;
for(int i = 1; i < n; i ++ )
if(a[i + 1].first != a[i].first)
s[k ++ ] = i * (a[i + 1].first - a[i].first);
s[k] = n;
for(int i = 1; i <= k; i ++ ) s[i] += s[i - 1];
ll p = 0;
for(int i = 1; i <= k; i ++ )
if(s[i] > q)
{
p = i;
break;
}

ll mi = p;
for(int i = 1; i <= n; i ++ )
if(a[i].first < p && a[i].second < p - a[i].first)
mi = min(mi, a[i].second + a[i].first);

cout << mi;

return 0;
}
``````

``````#include<iostream>
#include<set>
using namespace std;
typedef long long ll;
const int N = 610;
int t[N][N];
bool v[N][N];
int dx[5] = {-1, 0, 1, 0};
int dy[5] = {0, 1, 0, -1};
int n, m;

struct Node
{
int first, second, time;
bool operator< (const Node h) const
{
if(time != h.time) return time < h.time;
else if(first != h.first) return first < h.first;
else return second < h.second;
}
};

void bfs()
{
set<Node> q;
q.insert({1, 1, t[1][1]});
v[1][1] = 1;

while(q.size())
{
auto w = *q.begin();
q.erase(q.begin());

for(int i = 0; i < 4; i ++ )
{
int x = w.first + dx[i], y = w.second + dy[i], z = w.time;
if(x < 1 || x > n || y < 1 || y > m) continue;
if(!v[x][y])
{
q.insert({x, y, z + t[x][y]});
v[x][y] = 1;
}
}

if(q.size() == 1) cout << (*q.begin()).time;
}
}

int main()
{
cin >> n >> m;
for(int i = 1; i <= n; i ++ )
for(int j = 1; j <= m; j ++ )
cin >> t[i][j];
bfs();

return 0;
}``````

...全文
15 回复 打赏 收藏 转发到动态 举报

50,584

• 近7日
• 近30日
• 至今

刷题！