首页 > 编程语言 >编程一小时2023.5.15

编程一小时2023.5.15

时间:2023-05-15 18:44:36浏览次数:45  
标签:opt 15 int 31 编程 y% start cost 2023.5

1.

#include<bits/stdc++.h>
using namespace std;
bool book[10000001];
int prime[100001];
int t=1;
void Prime(int x)
{
memset(book,0,sizeof(book));
for(int i=2;i<=x;i++){
if(!book[i])prime[t++]=i;
for(int j=1;prime[j]<=x/i;j++){
book[prime[j]*i]=1;
if(i%prime[j]==0)break;
}
}
}
int main()
{
Prime(1000000);
int n;
while(cin>>n)cout<<prime[n]<<'\n';
}

2.

#include<bits/stdc++.h>
using namespace std;
int a[13]={0,31,28,31,30,31,30,31,31,30,31,30,31};
int day(int n)
{
int y=n/10000;
int m=n%10000/100;
int d=n%10000%100;
a[2]=(y%4==0&&y%100!=0||y%400==0?29:28);
while(m--)d+=a[m];
while(y--)d+=(y%4==0&&y%100!=0||y%400==0?366:365);
return d;
}
int main()
{
int a,b;
while(cin>>a>>b)cout<<abs(day(a)-day(b))+1<<endl;
}

3.

#include <bits/stdc++.h>
using namespace std;
const int N = 8, INF = 0x3f3f3f3f;
int ex, ey;
int g[N][N];
int opt[6][6][4]; 
int res, ans;
int dx[4] = {-1, 0, 1, 0}, dy[4] = {0, 1, 0, -1};
struct node
{
int x, y, sum, status;
};
node start;
inline void bfs(node st)
{
queue<node> q;
q.push(st);
while (q.size())
{
auto t = q.front();
q.pop();
for (int i = 0; i < 4; i ++ )
{
int a = dx[i] + t.x, b = dy[i] + t.y;
if (a >= 0 && a < 6 && b >= 0 && b < 6)
{
int cost = t.status * g[a][b];
if (t.sum + cost < opt[a][b][cost % 4])
{
opt[a][b][cost % 4] = t.sum + cost;
node temp;
temp.x = a;
temp.y = b;
temp.sum = t.sum + cost;
temp.status = cost % 4 + 1;
q.push(temp);
}
}
}
}
}
inline void solve()
{
memset(opt, 0x3f, sizeof opt);
ans = INF;
for (int i = 0; i < 6; i ++ )
for (int j = 0; j < 6; j ++ )
cin >> g[i][j];
start.sum = 0, start.status = 1;
cin >> start.x >> start.y >> ex >> ey;
if (start.x == ex && start.y == ey)
{
puts("0");
return;
}
bfs(start);
for (int i = 0; i < 4; i ++ ) ans = min(ans, opt[ex][ey][i]);
cout << ans << endl;
}
int main()
{
ios::sync_with_stdio(0);
cin.tie(0), cout.tie(0);
solve();
return 0;
}

标签:opt,15,int,31,编程,y%,start,cost,2023.5
From: https://www.cnblogs.com/zbl040721/p/17402787.html

相关文章