Codeforces Round #318 [RussianCodeCup Thanks-Round] (Div. 2)

以后每做完一场CF,解题报告都写在一起吧

暴力||二分 A - Bear and Elections

题意:有n个候选人,第一个候选人可以贿赂其他人拿到他们的票,问最少要贿赂多少张票第一个人才能赢

分析:正解竟然是暴力!没敢写暴力,卡了很久,导致这场比赛差点爆零!二分的话可以优化,但对于这题来说好像不需要。。。

收获:以后CF div2的A题果断暴力

代码(暴力):

/************************************************
* Author        :Running_Time
* Created Time  :2015-8-30 0:40:46
* File Name     :A.cpp
 ************************************************/

#include <cstdio>
#include <algorithm>
#include <iostream>
#include <sstream>
#include <cstring>
#include <cmath>
#include <string>
#include <vector>
#include <queue>
#include <deque>
#include <stack>
#include <list>
#include <map>
#include <set>
#include <bitset>
#include <cstdlib>
#include <ctime>
using namespace std;

#define lson l, mid, rt << 1
#define rson mid + 1, r, rt << 1 | 1
typedef long long ll;
const int N = 1e3 + 10;
const int INF = 0x3f3f3f3f;
const int MOD = 1e9 + 7;
int a[N];
int n, x;

int main(void)    {
	scanf ("%d", &n);
	scanf ("%d", &a[0]);	n--;
	for (int i=1; i<=n; ++i)	scanf ("%d", &a[i]);
	int ans = 0;
	while (true)	{
		int mxi = 0;
		for (int i=1; i<=n; ++i)	{
			if (a[i] >= a[mxi])	mxi = i;
		}
		if (mxi == 0)	break;
		ans++;	a[0]++;	a[mxi]--;
	}
	printf ("%d\n", ans);

    return 0;
}

  

代码(二分):

/************************************************
* Author        :Running_Time
* Created Time  :2015-8-30 0:40:46
* File Name     :A.cpp
 ************************************************/

#include <cstdio>
#include <algorithm>
#include <iostream>
#include <sstream>
#include <cstring>
#include <cmath>
#include <string>
#include <vector>
#include <queue>
#include <deque>
#include <stack>
#include <list>
#include <map>
#include <set>
#include <bitset>
#include <cstdlib>
#include <ctime>
using namespace std;

#define lson l, mid, rt << 1
#define rson mid + 1, r, rt << 1 | 1
typedef long long ll;
const int N = 1e3 + 10;
const int INF = 0x3f3f3f3f;
const int MOD = 1e9 + 7;
int a[N];
int n;

bool cmp(int x, int y)	{
	return x > y;
}

bool check(int add)	{
	int y = a[0] + add;
	for (int i=1; i<=n; ++i)	{
		if (a[i] >= y)	{
			if (add <= 0)	return false;
			add -= (a[i] - (y - 1));
			if (add < 0)	return false;
		}
		else	break;
	}
	return true;
}

int main(void)    {
	scanf ("%d", &n);
	scanf ("%d", &a[0]);	n--;
	for (int i=1; i<=n; ++i)	scanf ("%d", &a[i]);
	sort (a+1, a+1+n, cmp);
	if (a[0] > a[1])	{
		puts ("0");	return 0;
	}
	int l = 0, r = 1000;
	while (l <= r)	{
		int mid = (l + r) >> 1;
		if (check (mid))	r = mid - 1;
		else l = mid + 1;
	}
	printf ("%d\n", l);

    return 0;
}

  

暴力 B - Bear and Three Musketeers

题意:找一个三元环并且三个点的度数和-6最小

分析:三元环做过一题。这题能暴力跑过,DFS不用写。枚举边的两个端点,再找是否存在另外一个点构成三元环就可以了

收获:CF div2 B也暴力过

代码:

/************************************************
* Author        :Running_Time
* Created Time  :2015-8-25 19:24:24
* File Name     :E_topo.cpp
 ************************************************/

#include <cstdio>
#include <algorithm>
#include <iostream>
#include <sstream>
#include <cstring>
#include <cmath>
#include <string>
#include <vector>
#include <queue>
#include <deque>
#include <stack>
#include <list>
#include <map>
#include <set>
#include <bitset>
#include <cstdlib>
#include <ctime>
using namespace std;

#define lson l, mid, rt << 1
#define rson mid + 1, r, rt << 1 | 1
typedef long long ll;
typedef pair<int, int> PII;
const int N = 4e3 + 10;
const int INF = 0x3f3f3f3f;
const int MOD = 1e9 + 7;
int deg[N];
bool g[N][N];
vector<PII> G;
int n, m;

int main(void)    {
	scanf ("%d%d", &n, &m);
	G.clear ();
    memset (g, false, sizeof (g));
    memset (deg, 0, sizeof (deg));

	for (int u, v, i=1; i<=m; ++i) {
		scanf ("%d%d", &u, &v);
        G.push_back (PII (u, v));
	    g[u][v] = true;    g[v][u] = true;
        deg[u]++;   deg[v]++;
    }

	int ans = INF;
    for (int i=0; i<G.size (); ++i) {
        int u = G[i].first, v = G[i].second;
        for (int j=1; j<=n; ++j)    {
            if (g[u][j] && g[v][j]) {
                ans = min (ans, deg[u] + deg[v] + deg[j] - 6);
            }
        }
    }

	printf ("%d\n", (ans == INF) ? -1 : ans);

    return 0;
}

  

数学 C - Bear and Poker

时间: 2024-10-17 20:36:38

Codeforces Round #318 [RussianCodeCup Thanks-Round] (Div. 2)的相关文章

Codeforces Round #318 [RussianCodeCup Thanks-Round] (Div. 2) A. Bear and Elections(优先队列)

Limak is a grizzly bear who desires power and adoration. He wants to win in upcoming elections and rule over the Bearland. There are n candidates, including Limak. We know how many citizens are going to vote for each candidate. Now i-th candidate wou

Codeforces Round #318 [RussianCodeCup Thanks-Round] (Div. 2)——A二分——Bear and Elections

/*贪心WA一发..二分枚举加的数赛后发现直接暴力枚举1到1000也是可以的*//************************************************ * Author :Powatr * Created Time :2015-8-30 0:58:45 * File Name :A.cpp ************************************************/ #include <cstdio> #include <algorith

Codeforces Round #318 [RussianCodeCup Thanks-Round] (Div. 2)C. Bear and Poker(gcd模拟)

Limak is an old brown bear. He often plays poker with his friends. Today they went to a casino. There are n players (including Limak himself) and right now all of them have bids on the table. i-th of them has bid with size ai dollars. Each player can

Codeforces Round #318 [RussianCodeCup Thanks-Round] (Div. 2)——B纯暴力——Bear and Three Musketeers

/* 写搜索WA了..赛后发现直接暴力不会超啊,,, */ /************************************************ * Author :Powatr * Created Time :2015-8-30 14:55:10 * File Name :B.cpp ************************************************/ #include <cstdio> #include <algorithm> #in

Codeforces Round #318 [RussianCodeCup Thanks-Round] (Div. 2) B. Bear and Three Musketeers(STL_暴力)

Do you know a story about the three musketeers? Anyway, you will learn about its origins now. Richelimakieu is a cardinal in the city of Bearis. He is tired of dealing with crime by himself. He needs three brave warriors to help him to fight against

在青岛穷游打的cf codeforces Round #318 (Div. 2) A.Bear and Elections

这场cf是暑假集训后在青岛旅游打的一场,好累..... 题意:给出一个序列,要使a[1]大于a[2]~a[n],a[1]每次可以增加一,这个一从a[2]到a[[n]里面任意一个数减一扣除,求最少的步数 思路:要不断地修改值,并从中找出最大的,可以想到优先队列,还要保存下该数的编号,要知道在队首时是a[1].还有处里一种特殊情况,详见代码 总结:这道题并不难,我用了40多分钟,主要前面太急了,一开始并没有想到是优先队列,是一些其他的想法,只要合适一个样例就下手去做,导致有很明显的bug我竟然敲完代

Codeforces Round #318 (Div. 2) B Bear and Three Musketeers

不要想多了直接暴.对于u枚举a和b,判断一个是否连边,更新答案. #include<bits/stdc++.h> using namespace std; int n,m; const int maxn = 4001; #define PB push_back vector<int> G[maxn]; bool g[maxn][maxn]; int deg[maxn]; const int INF = 0x3f3f3f3f; int main() { //freopen("

Codeforces Round #318 (Div. 2) A Bear and Elections

优先队列模拟一下就好. #include<bits/stdc++.h> using namespace std; priority_queue<int>q; int main() { int n; scanf("%d",&n); int t; scanf("%d",&t); for(int i = 2; i <= n; i++){ int v; scanf("%d",&v); q.push(v

Codeforces Round #318 (Div. 2) C Bear and Poker

很简单,求一下所有数的2和3的幂是任意调整的,把2和3的因子除掉以后必须相等. #include<bits/stdc++.h> using namespace std; typedef long long ll; const int maxn = 1e5+5; ll a[maxn]; int main() { //freopen("in.txt","r",stdin); int n; scanf("%d",&n); for(i