A-Anagrams
不知道题意。
//#pragma comment(linker, "/STACK:1024000000,1024000000")
#include<algorithm>
#include<iostream>
#include<cstring>
#include<cstdio>
#include<vector>
#include<cmath>
#include<queue>
#include<stack>
#include<set>
#include<map>
#define xx first
#define yy second
#define LL long long
#define MP make_pair
#define INF 0x3f3f3f3f
#define lson l, m, rt << 1
#define rson m + 1, r, rt << 1|1
#define CLR(a, b) memset(a, b, sizeof(a))
using namespace std;
int main()
{
LL m;
scanf("%I64d", &m);
m --;
vector<LL> v;
for(LL tmp = 1; tmp * tmp <= m; tmp ++)
{
if(m % tmp) continue;
v.push_back(tmp);
if(m / tmp != tmp) v.push_back(m / tmp);
}
sort(v.begin(), v.end());
for(int i = 0; i < v.size(); i ++)
{
printf("%I64d ", v[i]);
}
return 0;
}
一个交互题,空间一点,告诉你当前猜的点相对于之前猜的点是否离所求点更近。显然x,y不相关。直接分别二分答案就好了。
//#pragma comment(linker, "/STACK:1024000000,1024000000")
#include<algorithm>
#include<iostream>
#include<cstring>
#include<cstdio>
#include<vector>
#include<cmath>
#include<queue>
#include<stack>
#include<set>
#include<map>
#define xx first
#define yy second
#define LL long long
#define MP make_pair
#define INF 0x3f3f3f3f
#define lson l, m, rt << 1
#define rson m + 1, r, rt << 1|1
#define CLR(a, b) memset(a, b, sizeof(a))
using namespace std;
int main()
{
int x, y = 0, op;
int l = 0, r = 1000000000;
printf("%d %d\n", l, y);
cout.flush();
scanf("%d", &op);
while(l < r)
{
printf("%d %d\n", r, y);
cout.flush();
scanf("%d", &op);
int mid = (l + r) >> 1;
if(op == 0) r = mid;
else l = mid + 1;
printf("%d %d\n", l, y);
cout.flush();
scanf("%d", &op);
}
x = l;
l = 0, r = 1000000000;
printf("%d %d\n", x, l);
cout.flush();
scanf("%d", &op);
while(l < r)
{
printf("%d %d\n", x, r);
cout.flush();
scanf("%d", &op);
int mid = (l + r) >> 1;
if(op == 0) r = mid;
else l = mid + 1;
printf("%d %d\n", x, l);
cout.flush();
scanf("%d", &op);
}
y = l;
printf("A %d %d\n", x, y);
cout.flush();
}
知道题意即可。
//#pragma comment(linker, "/STACK:1024000000,1024000000")
#include<algorithm>
#include<iostream>
#include<cstring>
#include<cstdio>
#include<vector>
#include<cmath>
#include<queue>
#include<stack>
#include<set>
#include<map>
#define xx first
#define yy second
#define LL long long
#define MP make_pair
#define INF 0x3f3f3f3f
#define lson l, m, rt << 1
#define rson m + 1, r, rt << 1|1
#define CLR(a, b) memset(a, b, sizeof(a))
using namespace std;
int main()
{
double h1, h2, t1, t2;
while(scanf("%lf%lf%lf%lf", &h2, &t2, &h1, &t1) != EOF)
{
double a = h1 - h2, b = - 2 * h1 * t2 + 2 * h2 * t1, c = h1 * t2 * t2 - h2 * t1 * t1;
double x1 = (-b + sqrt(b * b - 4 * a * c)) / (2 * a), x2 = (-b - sqrt(b * b - 4 * a * c)) / (2 * a);
printf("%.6f\n", min(x1, x2));
}
return 0;
}
E- Entertainment
大概考虑每个节点位置打架的情况,然后i和j打架,是可以把i和j独立提出来的。没具体做。
据队友计算,题目描述的距离计算和欧几里得距离相差不超过3?然后我们就枚举了凸包上各个直径一端的10*10的格子。实际上我们交了一下直接凸包直径的两个点也是可以AC的,正确性不详。
#include<map>
#include<vector>
#include<math.h>
#include<stdio.h>
#include<string.h>
#include<algorithm>
using namespace std;
typedef long long LL;
const int maxn = 200100;
const int mx = 1e7;
const double inf = 1e20;
LL sqr(LL x)
{
return x * x;
}
struct Point
{
LL x, y;
Point() {}
Point(LL x, LL y): x(x), y(y) {}
void input()
{
scanf("%I64d%I64d", &x, &y);
x += mx, y += mx;
}
} pnt[maxn], res[maxn], q[maxn];
LL mult(Point sp, Point ep, Point op)
{
return (sp.x - op.x) * (ep.y - op.y) - (ep.x - op.x) * (sp.y - op.y);
}
bool operator<(const Point &l, const Point &r)
{
return l.y < r.y || (l.y == r.y && l.x < r.x);
}
int graham(Point pnt[], int n, Point res[])
{
int i, len, k = 0, top = 1;
sort(pnt, pnt + n);
if(n == 0) return 0;
res[0] = pnt[0];
if(n == 1) return 1;
res[1] = pnt[1];
if(n == 2) return 2;
res[2] = pnt[2];
for(i = 2; i < n; i++)
{
while(top && mult(pnt[i], res[top], res[top - 1]) >= 0) top--;
res[++top] = pnt[i];
}
len = top;
res[++top] = pnt[n - 2];
for(i = n - 3; i >= 0; i--)
{
while(top != len && mult(pnt[i], res[top], res[top - 1]) >= 0) top--;
res[++top] = pnt[i];
}
return top;
}
map<LL, int> mp;
vector<int> tp[maxn];
LL gao(Point a)
{
return a.x * 100000000ll + a.y;
}
LL dist(Point a, Point b)
{
return sqr(a.x - b.x) + sqr(a.y - b.y);
}
double dist2(Point a, Point b)
{
LL mi = min(abs(a.x - b.x), abs(a.y - b.y));
LL mx = max(abs(a.x - b.x), abs(a.y - b.y));
return 0.0 + mx + sqrt(2.0) * mi - mi;
}
void solve(Point p[], int n)
{
double res = -inf;
int j = 1;
int ans1 = -1, ans2 = -1;
for(int i = 0; i < n; i++)
{
while(fabs(mult(p[(j + 1) % n], p[(i + 1) % n], p[i])) >
fabs(mult(p[j], p[(i + 1) % n], p[i]))) j = (j + 1) % n;
int idx = mp[gao(p[j])], idi = mp[gao(p[i])], idi1 = mp[gao(p[(i + 1) % n])];
for(int k = 0; k < tp[idx].size(); k++)
{
int v = tp[idx][k];
double dis = dist2(q[v], p[i]);
if(dis > res)
{
res = dis;
ans1 = v, ans2 = idi;
}
dis = dist2(q[v], p[(i + 1) % n]);
if(dis > res)
{
res = dis;
ans1 = v, ans2 = idi1;
}
}
}
printf("%d %d\n", ans1 + 1, ans2 + 1);
}
int main()
{
int n;
while(scanf("%d", &n) != EOF)
{
mp.clear();
for(int i = 0; i < n; i++)
{
pnt[i].input();
q[i] = pnt[i];
mp[gao(pnt[i])] = i;
tp[i].clear();
}
for(int i = 0; i < n; i++)
{
for(int j = pnt[i].x - 5; j <= pnt[i].x + 5; j++)
{
for(int k = pnt[i].y - 5; k <= pnt[i].y + 5; k++)
{
if(mp.count(gao(Point(j, k))) != 0) tp[i].push_back(mp[gao(Point(j, k))]);
}
}
}
int m = graham(pnt, n, res);
res[m] = res[0];
solve(res, m);
}
}
H- Hashing
这题因为a[i]的范围只有256,所以可以想到dp[i]的前驱不会在i-256之前,不然可以中间凭空产生一轮。于是就dp打法好了。
//#pragma comment(linker, "/STACK:1024000000,1024000000")
#include<algorithm>
#include<iostream>
#include<cstring>
#include<cstdio>
#include<vector>
#include<cmath>
#include<queue>
#include<stack>
#include<set>
#include<map>
#define xx first
#define yy second
#define LL long long
#define MP make_pair
#define INF 0x3f3f3f3f
#define lson l, m, rt << 1
#define rson m + 1, r, rt << 1|1
#define CLR(a, b) memset(a, b, sizeof(a))
using namespace std;
const int maxn = 100100;
int a[maxn], b[maxn][266];
int n;
LL dp[maxn][266];
void solve()
{
CLR(dp, -1);
dp[0][0] = 0;
b[0][0] = -1;
LL ans = 0;
for(int i = 1; i <= n; i ++)
{
for(int j = 0; j < 256; j ++) if(dp[i - 1][j] != -1)
{
int k = (j + 1) % 256;
if(dp[i - 1][j] + (a[i] ^ (b[i - 1][j] + 1)) > dp[i][k])
{
dp[i][k] = dp[i - 1][j] + (a[i] ^ (b[i - 1][j] + 1));
b[i][k] = b[i - 1][j] + 1;
}
if(dp[i - 1][j] > dp[i][j])
{
dp[i][j] = dp[i - 1][j];
b[i][j] = b[i - 1][j];
}
}
}
for(int i = 0; i < 256; i ++)
ans = max(ans, dp[n][i]);
printf("%I64d\n", ans);
}
int main()
{
while(scanf("%d", &n) != EOF)
{
for(int i = 1; i <= n; i ++)
{
scanf("%X", &a[i]);
}
solve();
}
return 0;
}
I- Illegal or Not?
水题。
//#pragma comment(linker, "/STACK:1024000000,1024000000")
#include<algorithm>
#include<iostream>
#include<cstring>
#include<cstdio>
#include<vector>
#include<cmath>
#include<queue>
#include<stack>
#include<set>
#include<map>
#define xx first
#define yy second
#define LL long long
#define MP make_pair
#define INF 0x3f3f3f3f
#define lson l, m, rt << 1
#define rson m + 1, r, rt << 1|1
#define CLR(a, b) memset(a, b, sizeof(a))
using namespace std;
int cnt[2000];
pair<int,int> mp[2000];
int main(){
int n;
while(scanf("%d",&n)!=EOF){
for(int i=0;i<n;i++){
int u,v;scanf("%d%d",&u,&v);
mp[i]=MP(u,v);
}
sort(mp,mp+n);
memset(cnt,0,sizeof(cnt));
for(int i=0;i<n;i++){
for(int j=mp[i].first;j<=mp[i].second;j++) cnt[j]=1;
}
for(int i = 1; i <= 1826; i ++)
{
cnt[i] += cnt[i - 1];
}
bool ok = true;
for(int i = 180; i <= 1826; i ++)
{
int tmp = cnt[i] - cnt[i - 180];
if(tmp > 90) ok = false;
}
if(ok) puts("Yes");
else puts("No");
}
return 0;
}
K- King's Rout
题意是让求是得小id尽量靠前,其实就是倒着拓扑的最大字典序。
#pragma comment(linker, "/STACK:1024000000,1024000000")
#include<algorithm>
#include<iostream>
#include<cstring>
#include<cstdio>
#include<vector>
#include<cmath>
#include<queue>
#include<stack>
#include<set>
#include<map>
#define xx first
#define yy second
#define LL long long
#define MP make_pair
#define INF 0x3f3f3f3f
#define lson l, m, rt << 1
#define rson m + 1, r, rt << 1|1
#define CLR(a, b) memset(a, b, sizeof(a))
using namespace std;
const int maxn = 200200;
vector<int> G[maxn];
int du[maxn];
int ans[maxn];
int n, m;
void solve()
{
int len = n;
priority_queue<int> Q;
for(int i = 1; i <= n; i ++)
{
if(du[i] == 0) Q.push(i);
}
while(!Q.empty())
{
int u = Q.top();
Q.pop();
ans[len --] = u;
for(int i = 0; i < G[u].size(); i ++)
{
int v = G[u][i];
du[v] --;
if(du[v] == 0) Q.push(v);
}
}
for(int i = 1; i <= n; i ++)
printf("%d%c", ans[i], i == n ? '\n' : ' ');
}
int main()
{
while(cin >> n >> m)
{
CLR(du, 0);
for(int i = 0; i <= n; i ++)
{
G[i].clear();
}
for(int i = 0; i < m; i ++)
{
int a, b;
scanf("%d%d", &a, &b);
G[b].push_back(a);
du[a] ++;
}
solve();
}
return 0;
}