• Educational Codeforces Round 155 (Rated for Div. 2)


    A. Rigged!

    链接 : 

    Problem - A - Codeforces

    思路 : 

    模拟题 :

    如果后面存在s>=s[1] 且 e>=e[1]的,那么不可能是第一个成为冠军,输出-1,否则取w[1]为ans; 

    代码 : 

    1. #include
    2. #define IOS ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
    3. #define endl '\n'
    4. using namespace std;
    5. typedef long long LL;
    6. int gcd(int a,int b){ return b==0 ? a : gcd(b,a%b); }
    7. int lcm(int a,int b){ if(a==0||b==0) return 0; return (a*b)/gcd(a,b); }
    8. bool is_prime(int x){if(x<2) return false;
    9. for(int i=2;i<=x/i;i++) if(x%i==0) return false; return true;}
    10. //numbers.erase(std::unique(numbers.begin(), numbers.end()), numbers.end()); // 去重操作
    11. const int N = 105;
    12. LL n,s[N],e[N];
    13. inline void solve(){
    14. cin>>n;
    15. LL ans = 0;
    16. for(int i=1;i<=n;i++) cin>>s[i]>>e[i];
    17. LL w = s[1];
    18. bool tag = false;
    19. for(int i=2;i<=n;i++){
    20. if(s[i]>=w && e[i]>=e[1]){
    21. tag = true;
    22. break;
    23. }
    24. }
    25. if(tag)
    26. cout << -1 << endl;
    27. else
    28. cout << w << endl;
    29. return ;
    30. }
    31. int main()
    32. {
    33. IOS
    34. int _;
    35. cin >> _;
    36. // _ = 1;
    37. while(_ --) solve();
    38. return 0;
    39. }

    B. Chips on the Board

    链接 : 

    Problem - B - Codeforces

    思路 :

    贪心,只有两种可能,取a中最小值所在的一行 或 b中最小值所在的一列,求和,答案就是两个中的较小值。

    代码 : 

    1. #include
    2. #define IOS ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
    3. #define endl '\n'
    4. using namespace std;
    5. typedef long long LL;
    6. int gcd(int a,int b){ return b==0 ? a : gcd(b,a%b); }
    7. int lcm(int a,int b){ if(a==0||b==0) return 0; return (a*b)/gcd(a,b); }
    8. bool is_prime(int x){if(x<2) return false;
    9. for(int i=2;i<=x/i;i++) if(x%i==0) return false; return true;}
    10. //numbers.erase(std::unique(numbers.begin(), numbers.end()), numbers.end()); // 去重操作
    11. const int N = 3e5+10;
    12. LL n , a[N] , b[N];
    13. inline void solve(){
    14. cin>>n;
    15. LL ma = 1e9+7 , mb = 1e9+7;
    16. LL sa = 0 , sb = 0;
    17. for(int i=1;i<=n;i++){
    18. cin >> a[i];
    19. ma = min(ma , a[i]);
    20. sa += a[i];
    21. }
    22. for(int i=1;i<=n;i++){
    23. cin >> b[i];
    24. mb = min(b[i] , mb);
    25. sb += b[i];
    26. }
    27. LL ans = min(n*ma+sb,n*mb+sa);
    28. cout << ans << endl;
    29. return ;
    30. }
    31. int main()
    32. {
    33. IOS
    34. int _;
    35. cin >> _;
    36. // _ = 1;
    37. while(_ --) solve();
    38. return 0;
    39. }

    C. Make it Alternating

    链接 : 

    Problem - C - Codeforces

    思路 : 

    一个排列组合问题:
    假设串 : 00011 , 那么必须选2个0 , 1个1删除 , 0的选择方案为C(3 , 2) = C(3 , 1) = 3 。1的选择方案为C(2 , 1) = 2 ,选出来三个数后,这三个数删除的顺序没有要求,所以有3!种方案,总方案数=C31 *C21*3!
    推及别的用例,都是获取连续的0串或1串,答案就是每个0串/1串的长度相乘,再乘以需要选择的数字个数的阶乘。

    代码 : 

    1. #include
    2. #define IOS ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
    3. #define endl '\n'
    4. using namespace std;
    5. typedef long long LL;
    6. const int p = 998244353,N=2e5+10;
    7. string s;
    8. LL f[N],g[N];
    9. LL qmi(int a,int b){
    10. int res = 1;
    11. while(b){
    12. if (b & 1) res = (LL)res * a % p;
    13. b >>= 1;
    14. a = (LL) a * a % p;
    15. }
    16. return res;
    17. }
    18. LL get(int a,int b){
    19. return (LL)f[a] * g[b] % p * g[a-b] % p;
    20. }
    21. LL fac(LL n){ // 求阶乘
    22. LL fact = 1;
    23. for(int i=1;i<=n;i++){
    24. fact = fact * i % p;
    25. }
    26. return fact;
    27. }
    28. inline void solve(){
    29. cin >> s ; s = ' ' + s;
    30. LL n = s.size();
    31. LL ans = 0 , res = 1;
    32. vector ant;
    33. for(int i=1;i<=n;i++){
    34. int j = i+1;
    35. while(j<=n && s[j]==s[i]) j++;
    36. int len = j - i;
    37. ans += len - 1;
    38. ant.push_back(len);
    39. i = j - 1;
    40. }
    41. LL ma = *max_element(ant.begin(), ant.end());
    42. LL fa = fac(ans);
    43. n = ant.size();
    44. f[0]=1 ; g[0] = 1;
    45. for (int i=1;i<=ma;i++){
    46. f[i] = f[i-1] * i % p;
    47. g[i] = (LL) g[i-1] * qmi(i , p-2 ) % p;
    48. }
    49. for(LL num : ant){
    50. res = (res * get(num,1)) % p;
    51. }
    52. res = ( res * fa ) % p;
    53. cout << ans << " " << res << endl;
    54. }
    55. int main()
    56. {
    57. IOS
    58. int _;
    59. cin >> _;
    60. while(_ --) solve();
    61. return 0;
    62. }


     

  • 相关阅读:
    资深java面试题及答案整理(四)
    网络编程 - TCP协议
    数据结构题型1--头插法建立单链表
    涉及多条件查询 使用mybatispluse的解决方法&&EasyCaptcha图形验证码工具
    金仓数据库 KingbaseES 插件参考手册 xml2
    每日一学—JavaScript Math对象
    攻防演练前 临战阶段:战前动员,鼓舞士气
    数据链路层
    力扣二分查找:第一个错误的版本
    3.Java中volatile 标记位的停止方法为什么不能用?
  • 原文地址:https://blog.csdn.net/ros275229/article/details/133281719