【LGR-194-Div.4】洛谷入门赛 #25

https://www.luogu.com.cn/contest/182049#problems

B4008 [语言月赛 202407] true

// Problem: B4008 [语言月赛 202407] true
// Contest: Luogu
// URL: https://www.luogu.com.cn/problem/B4008
// Memory Limit: 512 MB
// Time Limit: 1000 ms
// More thought is needed

#include <bits/stdc++.h>
#define endl '\n'
#define int long long
using namespace std;

void solve() {
  int a, b;
  cin >> a >> b;
  cout << a / 10 << " " << b * 10 << " " << 10000 - a / 10 - b * 10;
}

signed main() {
  ios::sync_with_stdio(false), cin.tie(nullptr), cout.tie(nullptr);
  solve();
  return 0;
}

B4009 [语言月赛 202407] value

// Problem: B4009 [语言月赛 202407] value
// Contest: Luogu
// URL: https://www.luogu.com.cn/problem/B4009
// Memory Limit: 512 MB
// Time Limit: 1000 ms
// More thought is needed

#include <bits/stdc++.h>
#define endl '\n'
#define int long long
using namespace std;

void solve() {
  int x, y, z, w;
  cin >> x >> y >> z >> w;
  if (!w && !z) {
    cout << "-1";
  }
  if (!z) {
    if (y == 0 || x != 0 || y % w != 0)
      cout << "-1";
    else
      cout << y / w;
    return;
  }
  if (!w) {
    if (x == 0 || y != 0 || x % z != 0)
      cout << "-1";
    else
      cout << x / z;
    return;
  }
  if (x / z == y / w && x % z == 0 && y % w == 0) {
    cout << x / z;
  } else
    cout << "-1";
}

signed main() {
  ios::sync_with_stdio(false), cin.tie(nullptr), cout.tie(nullptr);
  solve();
  return 0;
}

B4010 [语言月赛 202407] eating

// Problem: B4010 [语言月赛 202407] eating
// Contest: Luogu
// URL: https://www.luogu.com.cn/problem/B4010
// Memory Limit: 512 MB
// Time Limit: 1000 ms
// More thought is needed

#include <bits/stdc++.h>
#define endl '\n'
#define int long long
using namespace std;

void solve() {
  int n;
  cin >> n;
  double max_i = -1e9;
  int fuck;
  for (int i = 0; i < n; i++) {
    int a_i, b_i;
    cin >> a_i >> b_i;
    if (double(b_i) / double(a_i) > max_i) {
      max_i = double(b_i) / double(a_i);
      fuck = i;
    }
  }
  cout << fuck + 1;
}

signed main() {
  ios::sync_with_stdio(false), cin.tie(nullptr), cout.tie(nullptr);
  solve();
  return 0;
}

B4011 [语言月赛 202407] speech

// Problem: B4011 [语言月赛 202407] speech
// Contest: Luogu
// URL: https://www.luogu.com.cn/problem/B4011
// Memory Limit: 512 MB
// Time Limit: 1000 ms
// More thought is needed

#include <bits/stdc++.h>
#define endl '\n'
#define int long long
using namespace std;

void solve() {
  int n, m;
  int min_code;
  cin >> n >> m;
  vector<int> a_m(m, 0);
  for (int i = 0; i < m; i++) {
    int fuck;
    cin >> fuck;
    a_m[i] = fuck;
  }
  vector<int> a_n(m, 0);
  for (int i = 0; i < n; i++) {
    int fuckyou;
    cin >> fuckyou;
    a_n[fuckyou - 1]++;
  }
  int max_fuck = -1;
  for (int i = 0; i < m; i++) {
    if (a_m[i] * a_n[i] > max_fuck) {
      max_fuck = a_m[i] * a_n[i];
      min_code = i;
    }
  }
  cout << min_code + 1;
}

signed main() {
  ios::sync_with_stdio(false), cin.tie(nullptr), cout.tie(nullptr);
  solve();
  return 0;
}

B4012 [语言月赛 202407] rules

// Problem: B4012 [语言月赛 202407] rules
// Contest: Luogu
// URL: https://www.luogu.com.cn/problem/B4012
// Memory Limit: 512 MB
// Time Limit: 1000 ms
// More thought is needed

#include <bits/stdc++.h>
#define endl '\n'
#define int long long
using namespace std;

void solve() {
  int n, m, k;
  cin >> n >> m >> k;
  int fuck_num_all = 0;
  for (int i = 0; i < m; i++) {
    int fuck_num = 0;
    for (int j = 0; j < n; j++) {
      int fuck;
      cin >> fuck;
      if (fuck == k) {
        fuck_num++;
      }
    }
    if (fuck_num * 2 >= n) {
      fuck_num_all++;
    }
  }
  if (fuck_num_all * 2 >= m) {
    cout << "YES";
  } else {
    cout << "NO";
  }
}

signed main() {
  ios::sync_with_stdio(false), cin.tie(nullptr), cout.tie(nullptr);
  solve();
  return 0;
}

B4013 [语言月赛 202407] significance

// Problem: B4013 [语言月赛 202407] significance
// Contest: Luogu
// URL: https://www.luogu.com.cn/problem/B4013
// Memory Limit: 512 MB
// Time Limit: 1000 ms
// More thought is needed

#include <bits/stdc++.h>
#define endl '\n'
#define int long long
using namespace std;

void solve() {
  int n;
  cin >> n;
  vector<vector<int>> fuck(n + 1, vector<int>());
  int x_i;
  int j = 1;
  while (cin >> x_i) {
    for (int i = 1; i <= x_i; i++) {
      int fuck_i;
      cin >> fuck_i;
      fuck[j].push_back(fuck_i);
    }
    j++;
  }
  for (int i = 1; i <= n; i++) {
    int fuck_legth = fuck[i].size();
    int fuck_all = 0;
    for (int k = 0; k < fuck_legth; k++) {
      int fuck_size_i = fuck[fuck[i][k]].size();
      fuck[fuck[i][k]].erase(
          remove(fuck[fuck[i][k]].begin(), fuck[fuck[i][k]].end(), i),
          fuck[fuck[i][k]].end());
      fuck_all += fuck[fuck[i][k]].size();
      if (fuck[fuck[i][k]].size() != fuck_size_i) {
        fuck[fuck[i][k]].push_back(i);
      }
    }
    cout << fuck_all + fuck_legth << " ";
  }
}

signed main() {
  ios::sync_with_stdio(false), cin.tie(nullptr), cout.tie(nullptr);
  solve();
  return 0;
}

B4014 [语言月赛 202407] respect

// Problem: B4014 [语言月赛 202407] respect
// Contest: Luogu
// URL: https://www.luogu.com.cn/problem/B4014
// Memory Limit: 512 MB
// Time Limit: 1000 ms
// More thought is needed

#include <bits/stdc++.h>
#define endl '\n'
#define int long long
using namespace std;

void findstr(string& sub_i, int& fuck) {
  unsigned int position = 0;
  while ((position = sub_i.find("respect", position)) != string::npos) {
    position++;
    fuck++;
  }
}
void solve() {
  int n;
  cin >> n;
  for (int i = 0; i < n; i++) {
    string s;
    cin >> s;
    int k;
    int fuck = 0;
    cin >> k;
    if (k == 0) {
      findstr(s, fuck);
      cout << fuck << endl;
      continue;
    } else {
      int p_i_next = 0;
      for (int j = 0; j < k; j++) {
        int p_i;
        cin >> p_i;
        string sub_i = s.substr(p_i_next, p_i);
        findstr(sub_i, fuck);
        p_i_next = p_i;
      }
      string sub_i_end = s.substr(p_i_next, s.length());
      findstr(sub_i_end, fuck);
    }
    cout << fuck << endl;
  }
}

signed main() {
  ios::sync_with_stdio(false), cin.tie(nullptr), cout.tie(nullptr);
  solve();
  return 0;
}

不知道为什么通过不了,在本机上可以AC

题解:

// Problem: B4014 [语言月赛 202407] respect
// Contest: Luogu
// URL: https://www.luogu.com.cn/problem/B4014
// Memory Limit: 512 MB
// Time Limit: 1000 ms
// More thought is needed

#include <bits/stdc++.h>
#define endl '\n'
#define int long long
using namespace std;
int a[1001];
signed main() {
  int n;
  cin >> n;
  while (n--) {
    string s;
    int k;
    cin >> s >> k;
    for (int i = 1; i <= k; i++) {
      cin >> a[i];
    }
    a[k + 1] = s.length();
    int cnt = 0;
    for (int i = 1; i <= k + 1; i++) {
      string t = s.substr(a[i - 1], a[i] - a[i - 1]);
      if (t.find("respect") != string::npos) ++cnt;
    }
    cout << cnt << endl;
  }
}

//感觉没什么区别

B4015 [语言月赛 202407] accomplishment

// Problem: B4015 [语言月赛 202407] accomplishment
// Contest: Luogu
// URL: https://www.luogu.com.cn/problem/B4015
// Memory Limit: 512 MB
// Time Limit: 1000 ms
// More thought is needed

#include <bits/stdc++.h>
using namespace std;
//#define endl '\n'
#define int long long
namespace Fread {
const int SIZE = 1 << 16;
char buf[SIZE], *S, *T;
inline char getchar() {
  if (S == T) {
    T = (S = buf) + fread(buf, 1, SIZE, stdin);
    if (S == T) return '\n';
  }
  return *S++;
}
}  // namespace Fread
namespace Fwrite {
const int SIZE = 1 << 16;
char buf[SIZE], *S = buf, *T = buf + SIZE;
inline void flush() {
  fwrite(buf, 1, S - buf, stdout);
  S = buf;
}
inline void putchar(char c) {
  *S++ = c;
  if (S == T) flush();
}
struct NTR {
  ~NTR() { flush(); }
} ztr;
}  // namespace Fwrite
#ifdef ONLINE_JUDGE
#define getchar Fread::getchar
#define putchar Fwrite::putchar
#endif
namespace Fastio {
struct Reader {
  template <typename T>
  Reader& operator>>(T& x) {
    char c = getchar();
    short f = 1;
    while (c < '0' || c > '9') {
      if (c == '-') f *= -1;
      c = getchar();
    }
    x = 0;
    while (c >= '0' && c <= '9') {
      x = (x << 1) + (x << 3) + (c ^ 48);
      c = getchar();
    }
    x *= f;
    return *this;
  }
  Reader& operator>>(double& x) {
    char c = getchar();
    short f = 1, s = 0;
    x = 0;
    double t = 0;
    while ((c < '0' || c > '9') && c != '.') {
      if (c == '-') f *= -1;
      c = getchar();
    }
    while (c >= '0' && c <= '9' && c != '.')
      x = x * 10 + (c ^ 48), c = getchar();
    if (c == '.')
      c = getchar();
    else
      return x *= f, *this;
    while (c >= '0' && c <= '9') t = t * 10 + (c ^ 48), s++, c = getchar();
    while (s--) t /= 10.0;
    x = (x + t) * f;
    return *this;
  }
  Reader& operator>>(long double& x) {
    char c = getchar();
    short f = 1, s = 0;
    x = 0;
    long double t = 0;
    while ((c < '0' || c > '9') && c != '.') {
      if (c == '-') f *= -1;
      c = getchar();
    }
    while (c >= '0' && c <= '9' && c != '.')
      x = x * 10 + (c ^ 48), c = getchar();
    if (c == '.')
      c = getchar();
    else
      return x *= f, *this;
    while (c >= '0' && c <= '9') t = t * 10 + (c ^ 48), s++, c = getchar();
    while (s--) t /= 10.0;
    x = (x + t) * f;
    return *this;
  }
  Reader& operator>>(__float128& x) {
    char c = getchar();
    short f = 1, s = 0;
    x = 0;
    __float128 t = 0;
    while ((c < '0' || c > '9') && c != '.') {
      if (c == '-') f *= -1;
      c = getchar();
    }
    while (c >= '0' && c <= '9' && c != '.')
      x = x * 10 + (c ^ 48), c = getchar();
    if (c == '.')
      c = getchar();
    else
      return x *= f, *this;
    while (c >= '0' && c <= '9') t = t * 10 + (c ^ 48), s++, c = getchar();
    while (s--) t /= 10.0;
    x = (x + t) * f;
    return *this;
  }
  Reader& operator>>(char& c) {
    c = getchar();
    while (c == '\n' || c == ' ' || c == '\r') c = getchar();
    return *this;
  }
  Reader& operator>>(char* str) {
    int len = 0;
    char c = getchar();
    while (c == '\n' || c == ' ' || c == '\r') c = getchar();
    while (c != '\n' && c != ' ' && c != '\r') str[len++] = c, c = getchar();
    str[len] = '\0';
    return *this;
  }
  Reader& operator>>(string& str) {
    char c = getchar();
    str.clear();
    while (c == '\n' || c == ' ' || c == '\r') c = getchar();
    while (c != '\n' && c != ' ' && c != '\r') str.push_back(c), c = getchar();
    return *this;
  }
  template <class _Tp>
  Reader& operator>>(vector<_Tp>& vec) {
    for (unsigned i = 0; i < vec.size(); i++) cin >> vec[i];
    return *this;
  }
  template <class _Tp, class _tp>
  Reader& operator>>(pair<_Tp, _tp>& a) {
    cin >> a.first >> a.second;
    return *this;
  }
  Reader() {}
} cin;
const char endl = '\n';
struct Writer {
  const int Setprecision = 6;
  typedef int mxdouble;
  template <typename T>
  Writer& operator<<(T x) {
    if (x == 0) return putchar('0'), *this;
    if (x < 0) putchar('-'), x = -x;
    static int sta[45];
    int top = 0;
    while (x) sta[++top] = x % 10, x /= 10;
    while (top) putchar(sta[top] + '0'), --top;
    return *this;
  }
  Writer& operator<<(double x) {
    if (x < 0) putchar('-'), x = -x;
    mxdouble _ = x;
    x -= (double)_;
    static int sta[45];
    int top = 0;
    while (_) sta[++top] = _ % 10, _ /= 10;
    if (!top) putchar('0');
    while (top) putchar(sta[top] + '0'), --top;
    putchar('.');
    for (int i = 0; i < Setprecision; i++) x *= 10;
    _ = x;
    while (_) sta[++top] = _ % 10, _ /= 10;
    for (int i = 0; i < Setprecision - top; i++) putchar('0');
    while (top) putchar(sta[top] + '0'), --top;
    return *this;
  }
  Writer& operator<<(long double x) {
    if (x < 0) putchar('-'), x = -x;
    mxdouble _ = x;
    x -= (long double)_;
    static int sta[45];
    int top = 0;
    while (_) sta[++top] = _ % 10, _ /= 10;
    if (!top) putchar('0');
    while (top) putchar(sta[top] + '0'), --top;
    putchar('.');
    for (int i = 0; i < Setprecision; i++) x *= 10;
    _ = x;
    while (_) sta[++top] = _ % 10, _ /= 10;
    for (int i = 0; i < Setprecision - top; i++) putchar('0');
    while (top) putchar(sta[top] + '0'), --top;
    return *this;
  }
  Writer& operator<<(__float128 x) {
    if (x < 0) putchar('-'), x = -x;
    mxdouble _ = x;
    x -= (__float128)_;
    static int sta[45];
    int top = 0;
    while (_) sta[++top] = _ % 10, _ /= 10;
    if (!top) putchar('0');
    while (top) putchar(sta[top] + '0'), --top;
    putchar('.');
    for (int i = 0; i < Setprecision; i++) x *= 10;
    _ = x;
    while (_) sta[++top] = _ % 10, _ /= 10;
    for (int i = 0; i < Setprecision - top; i++) putchar('0');
    while (top) putchar(sta[top] + '0'), --top;
    return *this;
  }
  Writer& operator<<(char c) {
    putchar(c);
    return *this;
  }
  Writer& operator<<(char* str) {
    int cur = 0;
    while (str[cur]) putchar(str[cur++]);
    return *this;
  }
  Writer& operator<<(const char* str) {
    int cur = 0;
    while (str[cur]) putchar(str[cur++]);
    return *this;
  }
  Writer& operator<<(string str) {
    int st = 0, ed = str.size();
    while (st < ed) putchar(str[st++]);
    return *this;
  }
  template <class _Tp>
  Writer& operator<<(vector<_Tp> vec) {
    for (unsigned i = 0; i < vec.size() - 1; i++) cout << vec[i] << " ";
    cout << vec[vec.size() - 1];
    return *this;
  }
  template <class _Tp, class _tp>
  Writer& operator<<(pair<_Tp, _tp> a) {
    cout << a.first << " " << a.second;
    return *this;
  }
  Writer() {}
} cout;
}  // namespace Fastio
#define cin Fastio ::cin
#define cout Fastio ::cout
#define endl Fastio ::endl

int a_i_j[1001][1001];
void solve() {
  int n, m;
  cin >> n >> m;
  int sum = 0;
  for (int i = 1; i <= n; i++) {
    for (int j = 1; j <= m; j++) {
      int a_i_j_num;
      cin >> a_i_j_num;
      a_i_j[i][j] = a_i_j_num;
    }
  }
  for (int i = 1; i <= n / 3; i++) {
    for (int j = 1; j <= m / 3; j++) {
      sum += a_i_j[3 * i - 1][3 * j - 1];
    }
  }
  cout << sum;
}
signed main() {
  // ios::sync_with_stdio(false), cin.tie(nullptr), cout.tie(nullptr);
  solve();
  return 0;
}

发表评论

您的邮箱地址不会被公开。 必填项已用 * 标注

滚动至顶部