Summer training round2 #5

A:正着DFS一次处理出每个节点有多少个优先级比他低的(包括自己)作为值v[i] 求A B 再反着DFS求优先级比自己高的求C

#include <bits/stdc++.h>
#include <cstring>
#include <iostream>
#include <algorithm>
#define EPS 1.0e-9
#define PI acos(-1.0)
#define INF 30000000
#define MOD 1000000007
#define mem(a,b) memset((a),b,sizeof(a))
#define TS printf("!!!\n")
#define pb push_back
#define pai pair<int,int>
//using ll = long long;
//using ull= unsigned long long;
//std::ios::sync_with_stdio(false);
using namespace std;
//priority_queue<int,vector<int>,greater<int>> que;
typedef long long ll;
typedef unsigned long long ull;
const int maxn=5005;
int value[maxn];
int number[maxn];
vector<int> pe[maxn];
vector<int> pe2[maxn];
//queue<int> que;
void dfsgo(int x)
{
 number[x]++;
 int len=pe2[x].size();
 for(int i=0;i<len;i++)
 {
        if(!value[pe2[x][i]])
        {
        value[pe2[x][i]]=1;
        dfsgo(pe2[x][i]);
        }
 }
}
void dfsback(int x)
{
 number[x]++;
 int len=pe[x].size();
 for(int i=0;i<len;i++)
 {
        if(!value[pe[x][i]])
        {
        value[pe[x][i]]=1;
        dfsback(pe[x][i]);
        }
 }
}
int main()
{
 int a,b,e,p;
 int anser1=0;
 int anser2=0;
 int anser3=0;
 cin >> a >> b >> e >> p;
 mem(value,0);
 mem(number,0);
 int now,to;
 for(int i=1;i<=p;i++)
 {
        scanf("%d %d",&now,&to);
        pe[now].pb(to);
        pe2[to].pb(now);
 }
 for(int i=0;i<e;i++)
 {
        mem(value,0);
        value[i]=1;
        dfsgo(i);
 }
 //for(int i=0;i<e;i++)
 //cout<<number[i]<<" ";
 //cout<<endl;
 for(int i=0;i<e;i++)
{
 int curr=number[i];
 if(e-curr<a)
 anser1++;
 if(e-curr<b)
 anser2++;
}
 mem(number,0);
 for(int i=0;i<e;i++)
 {
        mem(value,0);
        value[i]=1;
        dfsback(i);
 }

 for(int i=0;i<e;i++)
 if(number[i]>b)
 anser3++;
 cout<<anser1<<endl<<anser2<<endl<<anser3;
}

C:哈夫曼树做法

D:签到题 直接暴力

E:递推DP

#include <bits/stdc++.h>
#include <cstring>
#include <iostream>
#include <algorithm>
#define EPS 1.0e-9
#define PI acos(-1.0)
#define INF 30000000
#define MOD 1000000007
#define mem(a,b) memset((a),b,sizeof(a))
#define TS printf("!!!\n")
#define pb push_back
#define pai pair<int,int>
//using ll = long long;
//using ull= unsigned long long;
//std::ios::sync_with_stdio(false);
using namespace std;
//priority_queue<int,vector<int>,greater<int>> que;
typedef long long ll;
typedef unsigned long long ull;
ll mod=2147483647;
int a[2005];
ll ans[2010][2010];
ll anser=0;
int main()
{
 int n;
 while(~scanf("%d",&n))
 {
 //mem(ans,0);
 anser=0;
 int x;
 ll minn;
 ll maxn;
 ll now;
 for(int i=0;i<=n;i++)
 scanf("%d",&a[i]);
 ans[1][a[0]]=1;
 for(int i=2;i<=n;i++)
        for(int j=1;j<=n+1;j++)
        {
        minn=min(a[i-1],j);
        maxn=max(a[i-1],j);
        now=a[i];
        if(now>minn)
        {
        ans[i][minn]=(ans[i][minn]+ans[i-1][j])%mod;
        }
        if(now<maxn)
        {
        ans[i][maxn]=(ans[i][maxn]+ans[i-1][j])%mod;
        }
        }
 for(int i=1;i<=n+1;i++)
 anser+=ans[n][i];
 cout<<anser%mod<<endl;
 }
}

F!:网络流

G:SG函数

H:问区间[x,y]中有多少数的二进制表示是ABAB..AB型或者A型的,其中A是n个1,B是m个0,n,m>0  直接暴力

J:凸包+扫描线+二分

给出l个大点和s个小点,问有多少小点被三个大点组成的三角形覆盖

#include <bits/stdc++.h>
#define MN 10010
#define pi acos(-1.0)
using namespace std;
typedef long long LL;

struct Point {
    LL x, y;

    Point(LL x = 0, LL y = 0) : x(x), y(y) {}

    bool operator<(const Point &rhs) const { return x < rhs.x || (x == rhs.x && y < rhs.y); }

    Point operator-(const Point &rhs) const { return Point(x - rhs.x, y - rhs.y); }

    LL operator^(const Point &rhs) const { return x * rhs.y - y * rhs.x; }
} a[MN], p[MN];

int n, tot;

void ConvexHull() {
    sort(a + 1, a + 1 + n);
    tot = 0;
    for (int i = 1; i <= n; i++) {
        while (tot > 1 && ((p[tot - 1] - p[tot - 2]) ^ (a[i] - p[tot - 2])) <= 0)tot--;
        p[tot++] = a[i];
    }
    int k = tot;
    for (int i = n - 1; i > 0; i--) {
        while (tot > k && ((p[tot - 1] - p[tot - 2]) ^ (a[i] - p[tot - 2])) <= 0)tot--;
        p[tot++] = a[i];
    }
    if (n > 1)tot--;
}

bool Judge(Point A) {
    int l = 1, r = tot - 2, mid;
    while (l <= r) {
        mid = (l + r) / 2;
        LL a1 = (p[mid] - p[0]) ^ (A - p[0]);
        LL a2 = (p[mid + 1] - p[0]) ^ (A - p[0]);
        if (a1 >= 0 && a2 <= 0) {
            if (((p[mid + 1] - p[mid]) ^ (A - p[mid])) >= 0)return true;
            return false;
        } else if (a1 < 0) {
            r = mid - 1;
        } else {
            l = mid + 1;
        }
    }
    return false;
}

int s, ans = 0;

int main() {
    cin >> n;
    for (int i = 1; i <= n; i++) cin >> a[i].x >> a[i].y;;
    ConvexHull();
    cin >> s;
    Point t;
    for (int i = 1; i <= s; i++) {
        cin >> t.x >> t.y;
        if (Judge(t)) ans++;
    }
    printf("%d", ans);
    return 0;
}

时间: 2024-10-05 23:27:06

Summer training round2 #5的相关文章

Summer training round2 #9(Training28)

A:签到题 C:模拟搜索题 #include <bits/stdc++.h> #include <cstring> #include <iostream> #include <algorithm> #include<queue> #define EPS 1.0e-9 #define PI acos(-1.0) #define INF 30000000 #define MOD 1000000007 #define mem(a,b) memset((

Summer training round2 #8(Training26)

A:贪心DFS 先从最远的搜起 如果一个点的value>=2 就ans++ D:并查集 E:大模拟 F:快速幂 #include <bits/stdc++.h> using namespace std; typedef long long LL; typedef pair<LL, LL > pLL; const LL MOD1 = 1e9 + 7, MOD2 = 1e9 + 9; int n, a[1000], vis[1000], i, j, k; set<pLL&g

Summer training round2 #6 (Training #26)

A:树遍历 DFS 贪心 先从最远的点开始判 如果某个点连有的算上自身的junction不小于二就ans++ return 0 连有的算上自身的junction为一 就return 1 #include <bits/stdc++.h> #include <cstring> #include <iostream> #include <algorithm> #define INF 0x3f3f3f3f #define MOD 1000000007 #define

Summer training round2 #1

A:水 B:求两个三角形之间的位置关系:相交 相离 内含 ①用三个点是否在三角形内外判断    计算MA*MB.MB*MC.MC*MA的大小 若这三个值同号,那么在三角形的内部,异号在外部 #include<stdio.h> #include<math.h> #include<string.h> #include<iostream> #include<algorithm> #define INF 2139062143 #define inf -2

Android官方开发文档Training系列课程中文版:手势处理之滚动动画及Scroller

原文地址:http://android.xsoftlab.net/training/gestures/scroll.html 在Android中,滑动经常由ScrollView类来实现.任何超出容器边界的布局都应该将自己内嵌在ScrollView中,以便提供可滚动的视图效果.自定义滚动只有在特定的场景下才会被用到.这节课将会描述这样一种场景:使用scroller显示一种可滚动的效果. 你可以使用Scroller或者OverScroller来收集一些滑动动画所需要的数据.这两个类很相似,但是Ove

2017 UESTC Training for Data Structures

2017 UESTC Training for Data Structures A    水,找区间极差,RMQ怼上去. #include<bits/stdc++.h> using namespace std; #pragma comment(linker, "/STACK:102400000,102400000") #define rep(i,a,b) for (int i=a;i<=b;i++) #define per(i,b,a) for (int i=b;i&

WeChall_Training: Programming 1 (Training, Coding)

When you visit this link you receive a message.Submit the same message back to http://www.wechall.net/challenge/training/programming1/index.php?answer=the_messageYour timelimit is 1.337 seconds 解题: 先在浏览器获取自己的cookie,再用python写了个自动提交的程序,header加上自己的cooki

Training的第二十天

今天接着做前天的活,就是实现把下载下来的jpg格式的图片设置为桌面的功能.要实现这个功能的关键点一个是要调用API(SystemParametersInfo)更换桌面:二是要把下载下来的JPG格式的图片转换成Bmp格式的图片才能够应用为桌面. 由于对API没什么概念,所以我从网上查了下资料并从网上copy了有关该API变成C#的代码和把jpg格式的图片转换成bmp格式图片的代码.接着看懂了里面的代码便自己修改了一下.接下来的是完善这个程序和把它加入到windows自动启动的任务中. 对于程序的完

2014 Multi-University Training Contest 6 Apple Tree(数学题)

题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4925 Apple Tree Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 262144/262144 K (Java/Others) Total Submission(s): 176    Accepted Submission(s): 120 Problem Description I've bought an orchard an