codeforces 877 C. Slava and tanks(构造,思维)

本文提供了一道来自Codeforces比赛的题目877C的解决方案,该题涉及在1到n范围内放置炸弹以摧毁移动的坦克。文章详细介绍了策略:通过在偶数位置投放炸弹,迫使坦克移动到奇数位置,再重复此过程以确保每辆坦克被摧毁两次。代码中使用了C++实现这一策略。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

http://codeforces.com/contest/877/problem/C
题意:1~n上每个位置有一些坦克,你可以在任意位置丢炸弹,当你在x位置丢炸弹时,x上的坦克会跑到x-1和x+1位置上,每个坦克需要炸两次,问最小次数炸毁所有坦克的方法

自己做的时候没想到…
思路:既然他会往左右跑,那么一开始炸偶数点,让它们跑到奇数点,再炸一次奇数点,它又会跑到偶数点,再炸一次偶数点…

#include<bits/stdc++.h>
#define fi first
#define se second
#define log2(a) log(n)/log(2)
#define show(a) cout<<a<<endl;
#define show2(a,b) cout<<a<<" "<<b<<endl;
#define show3(a,b,c) cout<<a<<" "<<b<<" "<<c<<endl;
#define tim printf("Time cost : %lf s\n",(double)clock()/CLOCKS_PER_SEC);
using namespace std;
 
typedef long long ll;
typedef long long LL;
typedef pair<int, int> P;
typedef pair<P, ll> LP;
const ll inf = 1e18;
const int N = 2e6 + 10;
const ll mod = 1e9+7;
const int base = 131;
const double pi = acos ( -1 );
const double eps = 1e-8;
inline ll mul(ll x,ll y) { return (x*y-(ll)((long double)x*y/mod)*mod+mod)%mod;}
inline ll ksm(ll a,ll b) {ll ans=1;while(b){if(b&1)ans=mul(ans,a);a=mul(a,a),b>>=1;}return ans;}
 
#define a(i,j) a[(i-1)*m+(j)]
#define b(i,j) b[(i-1)*m+(j)]
 
unordered_map<ll, ll> mp;
 
 
ll n, m,sx,sy,x,y,z,ex,ey,k,a[N],b[N],c[N];
ll ans,t,flag;
ll num[1005][1005],vis[1005][1005];
vector<ll> v;
ll sum,cnt;
ll res[N];
 
int main()
{
 
 
	ios::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
 
	cin>>n;
	if(n==2)
	{
		cout<<3<<endl<<"2 1 2";
	}
	else
	{
		cout<<2*(n/2)+(n+1)/2<<endl;
		for(int i=2;i<=n;i+=2) cout<<i<<" ";
		for(int i=1;i<=n;i+=2) cout<<i<<" ";
		for(int i=2;i<=n;i+=2) cout<<i<<" ";
	}
 
}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值