Codeforces Educational Codeforces Round 62 (Rated for Div. 2) ABCD

A. Detective Book

傳送門:http://codeforces.com/contest/1140/problem/A

題意:

  一本書有 n 頁,每頁有第 ai 頁纔會解釋的祕密。每天讀新的一頁,直到所有今天讀到的祕密都被解答,問幾天讀完。

思路:

  跑一遍for循環,記最大的頁數 cnt 直到 cnt = i 一天就結束。

AC代碼:

#include<iostream>
#include<cstdio>
#include<cstring>
#include<string>
#include<cstdlib>
#include<utility>
#include<algorithm>
#include<utility>
#include<queue>
#include<vector>
#include<set>
#include<stack>
#include<cmath>
#include<map>
#include<ctime>
#include<functional>
#include<bitset>
#define P pair<int,int>
#define ll long long
#define ull unsigned long long
#define lson id*2,l,mid
#define rson id*2+1,mid+1,r
#define ls id*2
#define rs (id*2+1)
#define Mod(a,b) a<b?a:a%b+b
#define cl0(a) memset(a,0,sizeof(a))
#define cl1(a) memset(a,-1,sizeof(a))
using namespace std;

const ll M = 1e9 + 7;
const ll INF = 1e9;
const double _e = 10e-6;
const int maxn = 1e3 + 10;
const int matSize = 9;
const int dx[4] = { 0,0,1,-1 }, dy[4] = { 1,-1,0,0 };
const int _dx[8] = { -1,-1,-1,0,0,1,1,1 }, _dy[8] = { -1,0,1,-1,1,-1,0,1 };

int x, y, z;
char c;

int n;

int main()
{
	while(~scanf("%d",&n)) {
		int cnt = 1, ans = 0;
		for(int i=1;i<=n;i++) {
			scanf("%d", &x);
			cnt = max(cnt, x);
			if (cnt <= i)
				ans++;
		}
		printf("%d\n", ans);
	}
	return 0;
}

 

B. Good String

傳送門:http://codeforces.com/contest/1140/problem/B

題意:

  一個字符串只含有 '<' 和 '>','<' 能將其左邊一個字符刪去,'>'同理。一個字符串如果經過一系列操作能只剩一個字符,那麼叫做 Good String ,問給定的字符串至少刪去幾個字符才能成爲 Good String 。

思路:

  從左往右找第一個 '>'出現的位置,從右往左找第一個 '<'出現的位置,其中最小值就是答案。

AC代碼:

#include<iostream>
#include<cstdio>
#include<cstring>
#include<string>
#include<cstdlib>
#include<utility>
#include<algorithm>
#include<utility>
#include<queue>
#include<vector>
#include<set>
#include<stack>
#include<cmath>
#include<map>
#include<ctime>
#include<functional>
#include<bitset>
#define P pair<int,int>
#define ll long long
#define ull unsigned long long
#define lson id*2,l,mid
#define rson id*2+1,mid+1,r
#define ls id*2
#define rs (id*2+1)
#define Mod(a,b) a<b?a:a%b+b
#define cl0(a) memset(a,0,sizeof(a))
#define cl1(a) memset(a,-1,sizeof(a))
using namespace std;

const ll M = 1e9 + 7;
const ll INF = 1e9;
const double _e = 10e-6;
const int maxn = 1e3 + 10;
const int matSize = 9;
const int dx[4] = { 0,0,1,-1 }, dy[4] = { 1,-1,0,0 };
const int _dx[8] = { -1,-1,-1,0,0,1,1,1 }, _dy[8] = { -1,0,1,-1,1,-1,0,1 };

int x, y, z;
char c;

int n;
string str;

int main()
{
	int t;
	scanf("%d", &t);
	while(t--) {
		scanf("%d", &n);
		cin >> str;
		int len = str.length();
		int ans = n - 1;
		for(int i=0;i<len;i++) {
			if(str[i]=='>') {
				ans = min(ans, i);
				break;
			}
		}
		for (int i = len - 1; i >= 0;i--) {
			if (str[i] == '<') {
				ans = min(ans, (len - 1) - i);
				break;
			}
		}
		printf("%d\n", ans);
	}
	return 0;
}

 

C. Playlist

傳送門:http://codeforces.com/contest/1140/problem/C

題意:

  給 n 首歌,每首都含有 t , b 這兩個屬性,選取 k 首, pleasure = 所有 t 的和 * 其中最小的 b 。問 pleasure 最大多少。

思路:

 將 n 首歌按 b 從大到小排序,維護 k 首歌的 t 的和的最大值,不斷 * b更新 ans 即可。

AC代碼:

#include<iostream>
#include<cstdio>
#include<cstring>
#include<string>
#include<cstdlib>
#include<utility>
#include<algorithm>
#include<utility>
#include<queue>
#include<vector>
#include<set>
#include<stack>
#include<cmath>
#include<map>
#include<ctime>
#include<functional>
#include<bitset>
#define P pair<int,int>
#define ll long long
#define ull unsigned long long
#define lson id*2,l,mid
#define rson id*2+1,mid+1,r
#define ls id*2
#define rs (id*2+1)
#define Mod(a,b) a<b?a:a%b+b
#define cl0(a) memset(a,0,sizeof(a))
#define cl1(a) memset(a,-1,sizeof(a))
using namespace std;

const ll M = 1e9 + 7;
const ll INF = 1e18;
const double _e = 10e-6;
const int maxn = 1e3 + 10;
const int matSize = 9;
const int dx[4] = { 0,0,1,-1 }, dy[4] = { 1,-1,0,0 };
const int _dx[8] = { -1,-1,-1,0,0,1,1,1 }, _dy[8] = { -1,0,1,-1,1,-1,0,1 };

int x, y, z;
char c;

struct node {
	ll t, b;
};

int k, n;
node a[300010];

bool cmp(node a,node b)
{
	return a.b > b.b;
}

struct cmp1 {
	bool operator()(ll a,ll b){
		return a > b;
	}
};

int main()
{
	while (~scanf("%d%d", &n, &k)) {
		for (int i = 0; i < n; i++)
			scanf("%lld%lld", &a[i].t, &a[i].b);
		sort(a, a + n, cmp);
		ll ans = 0, tot = 0, minn = INF;
		priority_queue<ll, vector<ll>, cmp1> que;
		for (int i = 0; i<n; i++) {
			que.push(a[i].t);
			tot += a[i].t;
			if(que.size()>k) {
				tot -= que.top();
				que.pop();
			}
			minn = min(minn, a[i].b);
			ans = max(ans, tot*minn);
		}
		printf("%lld\n", ans);
	}
	return 0;
}

 

D. Minimum Triangulation

傳送門:http://codeforces.com/contest/1140/problem/D

題意:

  給一個正 n 邊形,頂點序號按逆時針方向。

  將正 n 邊形分割成若干個三角形,每個三角形的權值爲頂點序號的乘積,求最小的權值之和。

思路:

  不斷從點1分割就行了。

AC代碼:

#include<iostream>
#include<cstdio>
#include<cstring>
#include<string>
#include<cstdlib>
#include<utility>
#include<algorithm>
#include<utility>
#include<queue>
#include<vector>
#include<set>
#include<stack>
#include<cmath>
#include<map>
#include<ctime>
#include<functional>
#include<bitset>
#define P pair<int,int>
#define ll long long
#define ull unsigned long long
#define lson id*2,l,mid
#define rson id*2+1,mid+1,r
#define ls id*2
#define rs (id*2+1)
#define Mod(a,b) a<b?a:a%b+b
#define cl0(a) memset(a,0,sizeof(a))
#define cl1(a) memset(a,-1,sizeof(a))
using namespace std;

const ll M = 1e9 + 7;
const ll INF = 1e18;
const double _e = 10e-6;
const int maxn = 1e3 + 10;
const int matSize = 9;
const int dx[4] = { 0,0,1,-1 }, dy[4] = { 1,-1,0,0 };
const int _dx[8] = { -1,-1,-1,0,0,1,1,1 }, _dy[8] = { -1,0,1,-1,1,-1,0,1 };

int x, y, z;
char c;

int n;

int main()
{
	while (~scanf("%d", &n)) {
		ll ans = 0;
		for (int i = 3; i <= n; i++)
			ans += 1ll * i*(i - 1);
		printf("%lld\n", ans);
	}
	return 0;
}

 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章