题意都忘了,我找了之前ac的部分题目的代码,大家将就看一下吧,不会再问我。
A - Promotions
#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[10000];
int cnt2[10000];
vector<int> v[10000];
vector<int> g[10000];
bool vis[10000];
int bfs(int x) {
queue<int> q;
q.push(x);
vis[x] = true;
int ret = 0;
while(!q.empty()) {
int a = q.front();
q.pop();
for(int i = 0; i < v[a].size(); i ++) {
int to = v[a][i];
if(vis[to]) continue;
vis[to] = true;
ret ++;
q.push(to);
}
}
return ret;
}
int bfs2(int x) {
queue<int> q;
q.push(x);
vis[x] = true;
int ret = 0;
while(!q.empty()) {
int a = q.front();
q.pop();
for(int i = 0; i < g[a].size(); i ++) {
int to = g[a][i];
if(vis[to]) continue;
vis[to] = true;
ret ++;
q.push(to);
}
}
return ret;
}
int main() {
int a, b, e, p;
while(scanf("%d%d%d%d", &a, &b, &e, &p) != EOF) {
for(int i = 0; i < e; i ++) {
v[i].clear();
cnt[i] = 0;
cnt2[i] = 0;
}
for(int i = 0; i < p; i ++) {
int x, y;
scanf("%d%d", &x, &y);
v[y].push_back(x);
g[x].push_back(y);
}
for(int i = 0; i < e; i ++) {
for(int j = 0; j < e; j ++) {
vis[j] = false;
}
cnt[i] = bfs(i);
for(int j = 0; j < e; j ++) {
vis[j] = false;
}
cnt2[i] = bfs2(i);
}
int out1 = 0, out2 = 0, out3 = 0;
for(int i = 0; i < e; i ++) {
if(cnt[i] >= b) out3 ++;
if(cnt2[i] >= e - a) out1 ++;
if(cnt2[i] >= e - b) out2 ++;
}
printf("%d\n%d\n%d\n", out1, out2, out3);
}
return 0;
}
B - Black Vienna
#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;
char s[100][10];
int a[100];
int b[100];
int n;
vector<int> g[100];
int belong[100];
bool vis[100];
bool dfs(int u) {
for(int i = 0; i < g[u].size(); i ++) {
int v = g[u][i];
if(belong[v] != -1) {
if(belong[v] == belong[u]) return false;
} else {
belong[v] = 1 - belong[u];
if(!dfs(v)) return false;
}
}
return true;
}
bool initMy(int x, int y, int z) {
memset(belong, -1, sizeof belong);
belong[x] = belong[y] = belong[z] = 2;
for(int i = 0; i < 26; i ++) {
g[i].clear();
}
for(int i = 0; i < n; i ++) {
int u = s[i][0];
int v = s[i][1];
if(b[i] == 0) {
if(belong[u] != 2) {
if(belong[u] == -1) belong[u] = 1 - a[i];
else if(belong[u] != 1 - a[i]) return false;
}
if(belong[v] != 2) {
if(belong[v] == -1) belong[v] = 1 - a[i];
else if(belong[v] != 1 - a[i]) return false;
}
} else if(b[i] == 2) {
if(belong[u] == -1) belong[u] = a[i];
else if(belong[u] != a[i]) return false;
if(belong[v] == -1) belong[v] = a[i];
else if(belong[v] != a[i]) return false;
} else {
if(belong[u] == 2) {
if(belong[v] != -1 && belong[v] != a[i]) return false;
belong[v] = a[i];
continue;
}
if(belong[v] == 2) {
if(belong[u] != -1 && belong[u] != a[i]) return false;
belong[u] = a[i];
continue;
}
g[u].push_back(v);
g[v].push_back(u);
}
}
memset(vis, 0, sizeof vis);
for(int i = 0; i < 26; i ++) {
if(belong[i] != -1 && belong[i] != 2) {
if(!dfs(i)) return false;
}
}
for(int i = 0; i < 26; i ++) {
if(belong[i] != -1) continue;
belong[i] = 0;
if(!dfs(i)) return false;
}
return true;
}
bool judge(int x, int y, int z) {
if(!initMy(x, y, z)) return false;
return true;
}
int main() {
while(scanf("%d", &n) != EOF) {
for(int i = 0; i < n; i ++) {
scanf("%s%d%d", s[i], &a[i], &b[i]);
a[i] --;
s[i][0] -= 'A';
s[i][1] -= 'A';
}
int ans = 0;
for(int i = 0; i < 26; i ++) {
for(int j = i + 1; j < 26; j ++) {
for(int k = j + 1; k < 26; k ++) {
if(judge(i, j, k)) {
ans ++;
}
}
}
}
printf("%d\n", ans);
}
return 0;
}
/**
0
2
AB 1 1
AC 2 1
3
AB 1 1
AC 2 1
BC 2 1
3
AB 1 1
AC 2 1
BC 2 1
3
AB 1 1
AC 2 1
BC 2 1
3
AB 1 1
AC 2 1
BC 2 1
3
AB 1 1
AC 2 1
BC 2 1
3
AB 1 1
AC 2 1
BC 2 1
3
AB 1 1
AC 2 1
BC 2 1
3
AB 1 1
AC 2 1
BC 2 1
3
AB 1 1
AC 2 1
BC 2 1
*/
C - Canvas Painting
//#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 T, n;
scanf("%d", &T);
while(T --)
{
scanf("%d", &n);
priority_queue<LL> Q;
for(int i = 0; i < n; i ++)
{
LL a; scanf("%lld", &a);
Q.push(-a);
}
LL ans = 0;
while(true)
{
if(Q.size() == 1) break;
LL u = -Q.top(); Q.pop();
LL v = -Q.top(); Q.pop();
ans += u + v;
Q.push(-u - v);
}
printf("%lld\n", ans);
}
return 0;
}
D - Dice Cup
//#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 CLR(a, b) memset(a, b, sizeof(a))
using namespace std;
const int maxn = 111;
int cnt[maxn];
int main()
{
int n, m, flag = 0;
while(scanf("%d%d", &n, &m) != EOF)
{
CLR(cnt, 0);
for(int i = 1; i <= n; i ++)
{
for(int j = 1; j <= m; j ++)
cnt[i + j] ++;
}
vector<int> ans;
int tmp = 0;
for(int i = 2; i <= n + m; i ++)
{
if(cnt[i] > tmp)
{
tmp = cnt[i];
ans.clear(); ans.push_back(i);
}
else if(cnt[i] == tmp) ans.push_back(i);
}
if(flag) puts("");
flag = 1;
for(int i = 0; i < ans.size(); i ++)
printf("%d\n", ans[i]);
}
return 0;
}
E - Wooden Signs
//#pragma comment(linker, "/STACK:1024000000,1024000000")
#include<algorithm>
#include<iostream>
#include<cstring>
#include<cstdio>
#include<vector>
#include<bitset>
#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 = 2222;
LL dp[maxn][maxn];
int a[maxn];
const int MOD = 2147483647;
int main()
{
int n;
while(scanf("%d", &n) != EOF)
{
for(int i = 0; i <= n; i ++)
scanf("%d", &a[i]);
CLR(dp, 0);
dp[1][a[0]] = 1;
for(int i = 2; i <= n; i ++)
{
if(a[i] < a[i - 1])
{
for(int j = 1; j < a[i]; j ++)
{
dp[i][j] = dp[i - 1][j];
dp[i][a[i - 1]] += dp[i - 1][j];
}
for(int j = a[i]; j <= a[i - 1]; j ++)
{
dp[i][a[i - 1]] += dp[i - 1][j];
}
for(int j = a[i - 1] + 1; j <= n + 1; j ++)
{
dp[i][j] = dp[i - 1][j];
}
}
else
{
for(int j = 1; j < a[i - 1]; j ++)
{
dp[i][j] = dp[i - 1][j];
}
for(int j = a[i - 1]; j <= a[i]; j ++)
{
dp[i][a[i - 1]] += dp[i - 1][j];
}
for(int j = a[i] + 1; j <= n + 1; j ++)
{
dp[i][j] = dp[i - 1][j];
dp[i][a[i - 1]] += dp[i - 1][j];
}
}
dp[i][a[i - 1]] %= MOD;
}
LL ans = 0;
for(int i = 1; i <= n + 1; i ++)
{
ans += dp[n][i];
ans %= MOD;
}
printf("%lld\n", ans);
}
return 0;
}
G - Game of Cards
//#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 = 1111;
int a[maxn], sg[maxn];
int vis[maxn][maxn];
int k, cc;
int dfs(int n)
{
if(n == 0) return 0;
if(sg[n] != -1) return sg[n];
for(int i = 0; i <= min(k, n - 1); i ++)
{
int t = n - i - a[n - i];
if(t >= 0) vis[n][dfs(t)] = cc;
}
for(int j = 0; j < 1111; j ++) if(vis[n][j] != cc)
{
sg[n] = j;
break;
}
// printf("%d -- %d\n", n, sg[n]);
return sg[n];
}
int main()
{
int n;
while(scanf("%d%d", &n, &k) != EOF)
{
int ans = 0;
CLR(vis, 0);
for(int i = 1; i <= n; i ++)
{
cc = i;
int m; scanf("%d", &m);
CLR(sg, -1);
a[0] = 0;
for(int j = 1; j <= m; j ++)
scanf("%d", &a[j]);
// printf("%d --\n", dfs(m));
ans ^= dfs(m);
}
puts(ans ? "Alice can win." : "Bob will win.");
}
return 0;
}
H - Sheldon Numbers
//#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>
#include<unordered_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;
unsigned LL x, y;
vector<unsigned LL> vec;
void init()
{
unsigned LL a;
for(int i = 1; i <= 63; i ++)
{
a = (1llu << i) - 1;
vec.push_back(a);
for(int j = 1; i + j < 64; j ++)
{
unsigned LL tmp = 0;
int c = 0;
while(c + i + j <= 63)
{
tmp = (tmp << i) + a;
tmp = (tmp << j);
c += i + j;
vec.push_back(tmp);
}
tmp = a;
c = i;
while(c + i + j <= 63)
{
tmp = (tmp << j);
tmp = (tmp << i) + a;
c += i + j;
vec.push_back(tmp);
}
}
}
vec.push_back(1llu << 63);
sort(vec.begin(), vec.end());
}
int main()
{
init();
while(scanf("%llu%llu", &x, &y) != EOF)
{
int r = upper_bound(vec.begin(), vec.end(), y) - vec.begin();
int l = lower_bound(vec.begin(), vec.end(), x) - vec.begin();
printf("%d\n", r - l);
}
return 0;
}
J - Saint John Festival
//#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 double
#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;
struct Point{
LL x,y;
Point(){}
Point(LL x,LL y):x(x),y(y){}
Point operator+(const Point &a){
return Point(x+a.x,y+a.y);
}
Point operator-(const Point &a){
return Point(x-a.x,y-a.y);
}
Point operator/(const double &a){
return Point(x/a,y/a);
}
LL operator*(const Point &a){
return x*a.y-y*a.x;
}
void input(){
scanf("%lf%lf",&x,&y);
}
}L[50050],res[50050];
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&&(pnt[i]-res[top-1])*(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&&(pnt[i]-res[top-1])*(res[top]-res[top-1])>=0) top--;
res[++top]=pnt[i];
}
return top;
}
bool isin(Point a,int cnt){
Point g=(res[0]+res[(cnt/3)]+res[(2*cnt/3)])/3.0;
int l=0,r=cnt;
while(l+1<r){
int mid=(l+r)/2;
LL k=(res[l]-g)*(res[mid]-g);
LL res1=(res[l]-g)*(a-g);
LL res2=(res[mid]-g)*(a-g);
if(k>0){
if(res1>=0&&res2<0) r=mid;
else l=mid;
}else{
if(res1<0&&res2>=0) l=mid;
else r=mid;
}
}
r%=cnt;
LL z=(res[r]-a)*(res[l]-a);
if(z<=0) return 1;
else return 0;
}
int main(){
int n,m;
while(scanf("%d",&n)!=EOF){
for(int i=0;i<n;i++) L[i].input();
n=graham(L,n,res);
for(int i=0;i<n;i++) res[i+n]=res[i];
int ans=0;
scanf("%d",&m);
for(int i=0;i<m;i++){
Point p;p.input();
if(isin(p,n)) ans++;
}
printf("%d\n",ans);
}
}