URAL 2025 Line Fighting 水题、贪心、均分
2016-07-30 23:20
676 查看
B - Line Fighting
Time Limit:1000MS Memory Limit:65536KB 64bit IO Format:%I64d
& %I64u
Submit Status Practice URAL
2025
Description
Boxing, karate, sambo… The audience is sick of classic combat sports. That is why a popular sports channel launches a new competition format based on the traditional Russian entertainment called line fighting. There can be from
2 to k teams taking part in a competition,
and there are n fighters altogether in all the teams. Before the competition starts, the fighters are divided into teams: each fighter becomes a member of exactly one team. Two fighters fight each other if they are members
of different teams. The organizers believe
that the more the number of fights between fighters, the higher the popularity of a competition will be. Help the organizers to
distribute fighters between teams so as to maximize the number of fights and output this number.
Input
The first line contains the number of tests T (1 ≤ T ≤ 10). In each of the following T lines you are given a test: integers n and k
separated with a space (2 ≤ k ≤ n ≤ 10 4).
Output
For each test output the answer (one integer) in a separate line.
Sample Input
Source
UESTC 2016 Summer Training #17 Div.2
URAL 2025
My Solutiion
贪心
尽可能均摊 t = n/k; res = n - t*k; 然后res个 t+1, n - res 个t, 然后算下就好了
复杂度 O(n)
Thank you!
------from ProLights
Time Limit:1000MS Memory Limit:65536KB 64bit IO Format:%I64d
& %I64u
Submit Status Practice URAL
2025
Description
Boxing, karate, sambo… The audience is sick of classic combat sports. That is why a popular sports channel launches a new competition format based on the traditional Russian entertainment called line fighting. There can be from
2 to k teams taking part in a competition,
and there are n fighters altogether in all the teams. Before the competition starts, the fighters are divided into teams: each fighter becomes a member of exactly one team. Two fighters fight each other if they are members
of different teams. The organizers believe
that the more the number of fights between fighters, the higher the popularity of a competition will be. Help the organizers to
distribute fighters between teams so as to maximize the number of fights and output this number.
Input
The first line contains the number of tests T (1 ≤ T ≤ 10). In each of the following T lines you are given a test: integers n and k
separated with a space (2 ≤ k ≤ n ≤ 10 4).
Output
For each test output the answer (one integer) in a separate line.
Sample Input
input | output |
---|---|
3 6 3 5 5 4 2 | 12 10 4 |
UESTC 2016 Summer Training #17 Div.2
URAL 2025
My Solutiion
贪心
尽可能均摊 t = n/k; res = n - t*k; 然后res个 t+1, n - res 个t, 然后算下就好了
复杂度 O(n)
#include <iostream> #include <cstdio> using namespace std; typedef long long LL; const int maxn = 1e4 + 8; /* const LL Hash = 1e15 + 7; inline LL mod(LL a) { return a - (a/Hash)*Hash; } LL pow_mod(LL a, LL i) { if(i == 0) return mod(1); LL t = pow_mod(a, i>>1); t = mod(t*t); if(i & 1) t = mod(t*a); return t; } */ int val[maxn]; int main() { #ifdef LOCAL freopen("a.txt", "r", stdin); //freopen("b.txt", "w", stdout); #endif // LOCAL LL T, n, k, t, ans, res; scanf("%I64d", &T); while(T--){ ans = 0; scanf("%I64d%I64d", &n, &k); t = n/k; res = n - t*k; t++; for(int i = 1; i <= res; i++){ ans += t*(n - i*t); } n -= res*t; t--; for(int i = res+1; i <= k; i++){ if(i != k)ans += t*(n - (i - res)*t); } printf("%I64d\n", ans); } return 0; }
Thank you!
------from ProLights
相关文章推荐
- URAL 2025. Line Fighting (math)
- URAL - 2025 Line Fighting
- 贪心--均分纸牌
- URAL 1389 Roadworks 贪心
- codevs1098 均分纸牌(贪心)
- URAL 1876. Centipede's Morning (贪心)
- wikioi-天梯-普及一等-贪心-1098:均分纸牌
- wikioi天梯之1098 均分纸牌 贪心
- codevs1098 均分纸牌(贪心)
- URAL 2000. Grand Theft Array V(贪心啊)
- URAL 1787 Turn for MEGA (贪心 + 模拟)
- URAL 1995 Illegal spices 贪心构造
- codevs 1098 均分纸牌【贪心】
- [贪心]CODEVS-1098 均分纸牌
- [贪心] 均分纸牌 HUSTOJ3066(Noip2002)
- 【贪心】URAL - 1303 Minimal Coverage
- URAL 1826. Minefield 贪心
- 算法题:均分纸牌 - 贪心
- URAL 1901 Space Elevators(贪心)
- 贪心——均分纸牌