题意:有n支队伍,每两支队伍打两场比赛(主客场各一次),胜得3分,平得1分,输不得分,比赛结束之后会评选出一个梦之队,
梦之队满足以下条件:进球总数最多,胜利场数最多,丢求总数最少,三个都不能并列,求梦之队的最低排名
析:http://blog.csdn.net/l123012013048/article/details/44001543
1.让梦之队的胜利场的进球总数达到无穷大(当然这是不可能的),输的场都是进0球对方队伍进1球,平的场都是0:0的得分,
这样即使梦之队只赢一场也能达到进球总数最多了,其他队伍的平局的时候就让其丢求数大于梦之队的总丢球数,这样梦之队的丢球总数就是最少了
2.胜利场数最多,胜利场的得分是3分,要让梦之队的排名尽量低的话,胜利场数就不能太多,输的场数让其多一点
所以让梦之队只赢两场,其他队伍都赢1场,这样就能推出梦之队的排名了
队伍 赢 输 平 总分
梦之队 2 n-1 n-3 n+3
队伍1 1 1 2 n-4 2n-1
队伍2 1 1 2n-4 2n-1
其他队伍 1 0 2n-3 2n
由以上可以推出
n <= 3 时 梦之队第一名
n == 4 时 第二名
n > 4 时 最后一名
代码如下:
#pragma comment(linker, "/STACK:1024000000,1024000000")
#include <cstdio>
#include <string>
#include <cstdlib>
#include <cmath>
#include <iostream>
#include <cstring>
#include <set>
#include <queue>
#include <algorithm>
#include <vector>
#include <map>
#include <cctype>
#include <cmath>
#include <stack>
#define debug() puts("++++");
#define gcd(a, b) __gcd(a, b)
#define lson l,m,rt<<1
#define rson m+1,r,rt<<1|1
#define freopenr freopen("in.txt", "r", stdin)
#define freopenw freopen("out.txt", "w", stdout)
using namespace std;
typedef long long LL;
typedef unsigned long long ULL;
typedef pair<int, int> P;
const int INF = 0x3f3f3f3f;
const double inf = 0x3f3f3f3f3f3f;
const double PI = acos(-1.0);
const double eps = 1e-5;
const int maxn = 1e6 + 10;
const int mod = 1e6 + 10;
const int dr[] = {-1, 1, 0, 0};
const int dc[] = {0, 0, 1, -1};
const char *de[] = {"0000", "0001", "0010", "0011", "0100", "0101", "0110", "0111", "1000", "1001", "1010", "1011", "1100", "1101", "1110", "1111"};
int n, m;
const int mon[] = {0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
const int monn[] = {0, 31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
inline bool is_in(int r, int c){
return r >= 0 && r < n && c >= 0 && c < m;
}
int main(){
while(cin >> n && n)
if(n < 4) cout << "1" << endl;
else if(4 == n) cout << "2" << endl;
else cout << n << endl;
return 0;
}
浙公网安备 33010602011771号