标签:tor cin cst href include main || def 没有
# | Penalty | A | B1 | B2 | C1 | C2 | D | E | F |
---|---|---|---|---|---|---|---|---|---|
3 (483) | 464 | +0 0:06 | +1 01:13 | +3 01:12 | + 01:57 | + 01:56 |
第一个人离开时候不增加,第二个人离开时候隔一个走开
当m=0时,答案为0
n为偶数时,如果2m<=n那么答案为m,否则为n-m
n为奇数时,如果2m<=n那么答案为m,否则为n-m,可以发现奇偶是一样的
int n,m;
int main()
{
cin>>n>>m;
if(m == 0){
cout<<1<<endl;return 0;
}
else if(n == 1){
cout<<1<<endl;return 0;
}
else if(2 * m <= n){
cout<<m<<endl;
}
else cout<<n-m<<endl;
return 0;
}
做B题心态崩了,这到场上肯定被hack
case并不多,但一定要细心想
#include <stdio.h>
#include <iostream>
#include <cstdlib>
#include <cmath>
#include <cctype>
#include <string>
#include <cstring>
#include <algorithm>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <ctime>
#include <vector>
#include <fstream>
#include <list>
#include <iomanip>
#include <numeric>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
#define ms(s) memset(s, 0, sizeof(s))
const int inf = 0x3f3f3f3f;
const int N = 1e5+10;
int n,u[N],c[N],num[N],cnt;
int main()
{
cin>>n;
int res = 1;
for(int i=1;i<=n;i++){
scanf("%d",&u[i]);
if(c[u[i]] == 0){
c[u[i]] ++;
num[1]++;
cnt++;
}
else{
num[c[u[i]]] --;
c[u[i]]++;
num[c[u[i]]] ++;
}
if(num[c[u[i]]] == i)res = i;//case1
if(num[1] == i)res = i;//case2
if(i > 1 && c[u[i]] == 1 && (i-1) % (cnt-1) == 0 && num[(i-1)/(cnt-1)] == cnt-1)//case3.1
res = i;
if(num[c[u[i]]] * c[u[i]] == i-1){//case3.2
res = i;
}
if(num[c[u[i]]] == 1 && num[c[u[i]]-1] == cnt-1)res = i;
if(num[c[u[i]]] == cnt - 1 && num[c[u[i]]+1] == 1)res = i;
}
cout<<res<<endl;
return 0;
}
存下每条直线,平行的直线不计算到答案中
const int N = 1010;
int n;
int x[N],y[N];
map<pair<int,int> ,set<int > > mp;
int main()
{
cin>>n;
ll res = 0;
ll tot = 0;//直线总数
for(int i=1;i<=n;i++)scanf("%d%d",&x[i],&y[i]);
for(int i=1;i<=n;i++){
for(int j=1;j<=n;j++){
if(i == j)continue;
int x1 = x[i], x2 = x[j];
int y1 = y[i], y2 = y[j];
int dx = x[i] - x[j];
int dy = y[i] - y[j];
int g = __gcd(dx,dy);
dx /= g;dy /= g;
if(dx < 0 || (dx == 0 && dy < 0)){
dx = -dx;
dy = -dy;
}
int c = dx * y1 - dy * x1;//求解直线dx*y = dy * x + c
if(!mp[{dx,dy}].count(c)){//如果直线没有记录过
tot++;
mp[{dx,dy}].insert(c);
res += tot - mp[{dx,dy}].size();//tot要减去与它平行的直线
}
}
}
cout<<res<<endl;
return 0;
}
留坑
留坑
标签:tor cin cst href include main || def 没有
原文地址:https://www.cnblogs.com/1625--H/p/11361241.html