wjie

1.2万

wjie
2小时前
#include <iostream>
#include <cstdio>
#include <algorithm>
using namespace std;
const int N = 1e4 + 5;

struct Node{
int l, r;
bool operator < (const Node& a) const {
return l < a.l;
}
}nodes[N];

int main()
{
int n, m;
scanf("%d%d", &n, &m);
for (int i = 0; i < m; ++i) scanf("%d%d", &nodes[i].l, &nodes[i].r);
sort(nodes, nodes+m);

int l = nodes[0].l, r = nodes[0].r;
for (int i = 1; i < m; ++i)
{
if (nodes[i].l > r)
{
n -= r - l + 1;
l = nodes[i].l, r = nodes[i].r;
}
else r = max(r, nodes[i].r);
}
n -= r - l + 1;
printf("%d", n+1);
return 0;
}


wjie
2小时前
#include <iostream>
#include <cstdio>
#include <algorithm>
using namespace std;
const int N = 1e4 + 5;

struct Node{
int l, r;
bool operator < (const Node& a) const {
return l < a.l;
}
}nodes[N];

int main()
{
int n, m;
scanf("%d%d", &n, &m);
for (int i = 0; i < m; ++i) scanf("%d%d", &nodes[i].l, &nodes[i].r);
sort(nodes, nodes+m);

int l = nodes[0].l, r = nodes[0].r;
for (int i = 1; i < m; ++i)
{
if (nodes[i].l > r)
{
n -= r - l + 1;
l = nodes[i].l, r = nodes[i].r;
}
else r = max(r, nodes[i].r);
}
n -= r - l + 1;
printf("%d", n+1);
return 0;
}


wjie
1天前
#include <iostream>
#include <cstdio>
using namespace std;
const int N = 1e5 + 5;

int n, k, h[N], w[N];

bool judge(int x)
{
int num = 0;
for (int i = 0; i < n; ++i) num += (h[i] / x) * (w[i] / x);
return num >= k;
}

int main()
{
scanf("%d%d", &n, &k);
for (int i = 0; i < n; ++i) scanf("%d%d", &h[i], &w[i]);
int l = 1, r = N, res = 1;
while (l <= r)
{
int mid = (l + r) >> 1;
if (judge(mid))
{
res = mid;
l = mid + 1;
}
else r = mid - 1;
}
printf("%d", res);
return 0;
}


wjie
1天前
#include <iostream>
#include <cstdio>
using namespace std;
const int N = 1e5 + 5;

int n, k, h[N], w[N];

bool judge(int x)
{
int num = 0;
for (int i = 0; i < n; ++i) num += (h[i] / x) * (w[i] / x);
return num >= k;
}

int main()
{
scanf("%d%d", &n, &k);
for (int i = 0; i < n; ++i) scanf("%d%d", &h[i], &w[i]);
int l = 1, r = N, res = 1;
while (l <= r)
{
int mid = (l + r) >> 1;
if (judge(mid))
{
res = mid;
l = mid + 1;
}
else r = mid - 1;
}
printf("%d", res);
return 0;
}


wjie
2天前
#include <iostream>
#include <cstdio>
using namespace std;
const double eps = 1e-3;
const int N = 1e5 + 5;

int n, m;
double arr[N];

bool check(double length)
{
int num = 0;
for (int i = 0; i < n; ++i) num += (int)(arr[i] / length);
return num >= m;
}

int main()
{
scanf("%d%d", &n, &m);
for (int i = 0; i < n; ++i) scanf("%lf", &arr[i]);

double l = 0, r = 1e9;
while (r - l > eps)
{
double mid = (l + r) / 2.0;
if (check(mid)) l = mid;
else r = mid;
}
printf("%.2lf", r);
return 0;
}


wjie
2天前
#include <iostream>
#include <cstdio>
using namespace std;
const double eps = 1e-3;
const int N = 1e5 + 5;

int n, m;
double arr[N];

bool check(double length)
{
int num = 0;
for (int i = 0; i < n; ++i) num += (int)(arr[i] / length);
return num >= m;
}

int main()
{
scanf("%d%d", &n, &m);
for (int i = 0; i < n; ++i) scanf("%lf", &arr[i]);

double l = 0, r = 1e9;
while (r - l > eps)
{
double mid = (l + r) / 2.0;
if (check(mid)) l = mid;
else r = mid;
}
printf("%.2lf", r);
return 0;
}


wjie
3天前
#include <iostream>
#include <cstdio>
#include <vector>
using namespace std;

void work(int x, int n)
{
int y = x * x;
vector<int> vec2;
while (y)
{
vec2.push_back(y % n);
y /= n;
}
for (int i = 0; i < vec2.size()/2; ++i)
{
if (vec2[i] != vec2[vec2.size()-1-i]) return;
}

vector<int> vec1;
while (x)
{
vec1.push_back(x % n);
x /= n;
}
for (int i = vec1.size()-1; i >= 0; --i)
{
if (vec1[i] < 10) printf("%d", vec1[i]);
else printf("%c", vec1[i]-10+'A');
}
printf(" ");
for (int i = vec2.size()-1; i >= 0; --i)
{
if (vec2[i] < 10) printf("%d", vec2[i]);
else printf("%c", vec2[i]-10+'A');
}
puts("");
}

int main()
{
int n;
scanf("%d", &n);

for (int i = 1; i <= 300; ++i) work(i, n);
return 0;
}


wjie
3天前
#include <iostream>
#include <cstdio>
#include <vector>
using namespace std;

void work(int x, int n)
{
int y = x * x;
vector<int> vec2;
while (y)
{
vec2.push_back(y % n);
y /= n;
}
for (int i = 0; i < vec2.size()/2; ++i)
{
if (vec2[i] != vec2[vec2.size()-1-i]) return;
}

vector<int> vec1;
while (x)
{
vec1.push_back(x % n);
x /= n;
}
for (int i = vec1.size()-1; i >= 0; --i)
{
if (vec1[i] < 10) printf("%d", vec1[i]);
else printf("%c", vec1[i]-10+'A');
}
printf(" ");
for (int i = vec2.size()-1; i >= 0; --i)
{
if (vec2[i] < 10) printf("%d", vec2[i]);
else printf("%c", vec2[i]-10+'A');
}
puts("");
}

int main()
{
int n;
scanf("%d", &n);

for (int i = 1; i <= 300; ++i) work(i, n);
return 0;
}


wjie
4天前
#include <iostream>
#include <cstdio>
#include <cstring>
using namespace std;
const int N = 25;

char arr[N][N];
int n, m, res, st[N][N];
int dx[4] = {1, 0, 0, -1};
int dy[4] = {0, 1, -1, 0};

void dfs(int x, int y)
{
res ++;
st[x][y] = 1;
for (int i = 0; i < 4; ++i)
{
int nx = x + dx[i], ny = y + dy[i];
if (nx >= 0 && nx < n && ny >= 0 && ny < m && arr[nx][ny] != '#' && !st[nx][ny])
{
dfs(nx, ny);
}
}
}

int main()
{
while (scanf("%d%d", &m, &n) && n+m)
{
for (int i = 0; i < n; ++i) scanf("%s", arr[i]);
int x, y;
for (int i = 0; i < n; ++i)
{
for (int j = 0; j < m; ++j)
{
if (arr[i][j] == '@')
{
x = i, y = j;
break;
}
}
}
memset(st, 0, sizeof st);
res = 0;
dfs(x, y);
printf("%d\n", res);
}
return 0;
}


wjie
4天前
#include <iostream>
#include <cstdio>
#include <cstring>
using namespace std;
const int N = 25;

char arr[N][N];
int n, m, res, st[N][N];
int dx[4] = {1, 0, 0, -1};
int dy[4] = {0, 1, -1, 0};

void dfs(int x, int y)
{
res ++;
st[x][y] = 1;
for (int i = 0; i < 4; ++i)
{
int nx = x + dx[i], ny = y + dy[i];
if (nx >= 0 && nx < n && ny >= 0 && ny < m && arr[nx][ny] != '#' && !st[nx][ny])
{
dfs(nx, ny);
}
}
}

int main()
{
while (scanf("%d%d", &m, &n) && n+m)
{
for (int i = 0; i < n; ++i) scanf("%s", arr[i]);
int x, y;
for (int i = 0; i < n; ++i)
{
for (int j = 0; j < m; ++j)
{
if (arr[i][j] == '@')
{
x = i, y = j;
break;
}
}
}
memset(st, 0, sizeof st);
res = 0;
dfs(x, y);
printf("%d\n", res);
}
return 0;
}