本文主要是介绍Codeforces Round #249 (Div. 2) A B,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
C好像就是个模拟,D 是个编码复杂度大的,但是好像也就是枚举三角形,我这会儿准备区域赛,尽量找点思维难度大的,所以昨晚A B 还是去做区域赛题吧.....
B 也有点意思 贪心
题意:交换相邻两个位的数,然后最多换k次,求最大数
解法,找<=k范围内的最大数,与之交换,右移一位,继续找,直到k用完
//#pragma comment(linker, "/STACK:102400000,102400000")
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <string>
#include <iostream>
#include <iomanip>
#include <cmath>
#include <map>
#include <set>
#include <queue>
using namespace std;#define ls(rt) rt*2
#define rs(rt) rt*2+1
#define ll long long
#define ull unsigned long long
#define rep(i,s,e) for(int i=s;i<e;i++)
#define repe(i,s,e) for(int i=s;i<=e;i++)
#define CL(a,b) memset(a,b,sizeof(a))
#define IN(s) freopen(s,"r",stdin)
#define OUT(s) freopen(s,"w",stdout)
const ll ll_INF = ((ull)(-1))>>1;
const double EPS = 1e-8;
const double pi = acos(-1.0);
const int INF = 100000000;int num[65];
ll a;
int k;int change()
{ll t=a;int f=0;while(t){num[f++]=t%10;t/=10;}return f;
}void print()
{int id=64;while(!num[id])--id;//printf("%d",num[id]);for(int i=id;i>=0;i--)printf("%d",num[i]);putchar('\n');
}int main()
{while(~scanf("%I64d%d",&a,&k)){CL(num,0);int wei=change();wei--;for(int i=wei;i>=0;i--){int maxpos=i,mx=num[i],cnt=k;for(int j=i-1;j>=0 && cnt>=1;j--)//{cnt--;if(num[j] > mx){mx=num[j];maxpos=j;}}//k-=i-maxpos;//cout << "***************" << endl;//cout << "mx=" << mx << "pos=" << maxpos << endl;//print();///// printf("i=%d k=%d\n",i,k);//for(int j=i-1;j>=maxpos && k>=1;j--)//swap(num[j],num[j+1]),k--;for(int j=maxpos;j<=i-1&&k>=1;j++)swap(num[j],num[j+1]),k--;if(!k)break;}print();}return 0;
}
A 纯模拟暴力
//#pragma comment(linker, "/STACK:102400000,102400000")
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <string>
#include <iostream>
#include <iomanip>
#include <cmath>
#include <map>
#include <set>
#include <queue>
using namespace std;#define ls(rt) rt*2
#define rs(rt) rt*2+1
#define ll long long
#define ull unsigned long long
#define rep(i,s,e) for(int i=s;i<e;i++)
#define repe(i,s,e) for(int i=s;i<=e;i++)
#define CL(a,b) memset(a,b,sizeof(a))
#define IN(s) freopen(s,"r",stdin)
#define OUT(s) freopen(s,"w",stdout)
const ll ll_INF = ((ull)(-1))>>1;
const double EPS = 1e-8;
const double pi = acos(-1.0);
const int INF = 100000000;const int MAXN= 200;
int num[MAXN];int main()
{int n,m;while(~scanf("%d%d",&n,&m)){for(int i=0;i<n;i++)scanf("%d",&num[i]);int ans=0,d=0;for(int i=0;i<n;i++){if(m-d>=num[i]){d+=num[i];}else{ans++;d=num[i];}}printf("%d\n",ans+1);}return 0;
}
这篇关于Codeforces Round #249 (Div. 2) A B的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!