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 -2139062144
#define ll long long
using namespace std;
int x[8],y[8];
int dian(int a,int i,int j) {
    return (x[a] - x[i])*(x[a]-x[j]) + (y[a] - y[i]) * (y[a] - y[j]);
}
bool pan(int a,int b,int c) {
    int zheng = 0,fu = 0;
    if(a>0)    zheng++;
    if(b>0)    zheng++;
    if(c>0)    zheng++;
    fu = 3 - zheng;
    if(fu == 2 || fu == 3)    return true;
    else    return false;
}
int main() {
    int t;
    int i;
    scanf("%d",&t);
    bool xx[6];
    while(t--) {
        for(i=0; i<6; i++) {
            scanf("%d%d",&x[i],&y[i]);
        }
        for(i=0; i<3; i++) {
            xx[i] = pan(dian(i,3,4),dian(i,4,5),dian(i,3,5));
//            printf("fuck:%d %d %d\n",dian(i,3,4),dian(i,4,5),dian(i,3,5));
        }
        for(i=3; i<6; i++) {
            xx[i] = pan(dian(i,0,1),dian(i,0,2),dian(i,1,2));
//            printf("fuck:%d %d %d\n",dian(i,0,1),dian(i,0,2),dian(i,1,2));
        }
//        for(i=0; i<6; i++)    printf("%d ",xx[i]);
        if(xx[0] == true && xx[1] == true && xx[2] == true) {
            printf("contain\n");
            continue;
        }
        if(xx[3] == true && xx[4] == true && xx[5] == true) {
            printf("contain\n");
            continue;
        }
        if(xx[0] == false && xx[1] == false && xx[2] == false && xx[3] == false && xx[4] == false && xx[5] == false) {
            printf("disjoint\n");
            continue;
        }
        printf("intersect\n");
    }
    return 0;
}

D:KMP加上特殊情况判断

#include<stdio.h>
#include<math.h>
#include<string.h>
#include<iostream>
#include<algorithm>
#define INF 2139062143
#define inf -2139062144
#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 namespace std;
string ori,pat;
int n,nxt[1001000],ans=0;
int GetNext()
{
    nxt[0]=nxt[1]=0;
    for(int i=1;i<pat.size();i++)
    {
        int j=nxt[i];
        while(j&&pat[i]!=pat[j])j=nxt[j];
        nxt[i+1]=((pat[i]==pat[j])?j+1:0);
    }
}
int Kmp()
{
    memset(nxt,0,sizeof(nxt));
    GetNext();
    int j=0;
    for(int i=0;i<ori.size();i++)
    {
        while(j&&ori[i]!=pat[j])j=nxt[j];
        if(ori[i]==pat[j])j++;
        if(j==pat.size())ans++;
    }
}
int main()
{
    scanf("%d",&n);
    for(int i=1;i<=n;i++)
    {
        cin>>ori>>pat;
        if(pat.size()>ori.size())
        {
            cout<<"Bob"<<endl;
        }else
        {
            int flag1=0,flag2=0;
            ans=0;Kmp();
            if(ans)flag1=1;
            reverse(pat.begin(),pat.end());
            string t="";
            int j;
            for(j=0;j<pat.size();j++)
            {
                if(pat[j]!=‘0‘)break;
            }
            for(;j<pat.size();j++)
            {
                t+=pat[j];
            }
            pat=t;
            ans=0;Kmp();
            if(ans)flag2=1;
            if(flag1||flag2)cout<<"Alice"<<endl;else cout<<"Bob"<<endl;
        }
    }
    return 0;
}

G:猜公式(JAVA)

import java.math.BigInteger;
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        int t;
        Scanner input = new Scanner(System.in);
        t = input.nextInt();
        while (t-- > 0) {
//           BigInteger n = input.nextBigInteger();
            int n = input.nextInt();
            BigInteger flag = BigInteger.valueOf(1);
           for(int i = 1;i<=n;i++){
                    flag = flag.multiply(BigInteger.valueOf(i));
           }
           BigInteger ans = BigInteger.valueOf(0);
            for(int i = 1;i<=n;i++){
               ans = ans.add(flag.divide(BigInteger.valueOf(i)));
            }
            System.out.println(ans + ".0");
        }
    }
}

F:DFS序加树状数组  子节点增加的值为x+dep[v]?k?dep[s]?k,那么维护两个值x+dep[v]*k与-k,用两个树状数组维护这两个值,做到区间修改,单点查询

I:哈希加暴力 或者直接用strcmp函数判

K:错排加逆元加快速幂

#include<stdio.h>
#include<math.h>
#include<string.h>
#include<iostream>
#include<algorithm>
#define INF 2139062143
#define inf -2139062144
#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;
typedef pair<int,int> pai1;
const double EPS=1e-8;
const double PI=acos(-1);
ll mod=1000000007;
const int maxn=10005;
ll cuo[maxn];
ll ni[maxn];
ll jie[maxn];
ll quick_pow(ll a,ll n)
{
    ll result=1;
    while(n>0)
    {
        if(n&1)
        result=(result*a)%mod;
        a=(a*a)%mod;
        n/=2;
    }
    return result;
}
void init()
{
 cuo[0]=1;
 cuo[1]=0;
 for(int i=2;i<=10000;i++)
 cuo[i]=(i-1)*(cuo[i-1]+cuo[i-2])%mod;
 ni[1]=jie[1]=1;
 jie[1]=ni[1]=ni[0]=jie[0]=1;
 for(int i=2;i<=10000;i++)
 {
  jie[i]=i*jie[i-1]%mod;
  ni[i]=quick_pow(jie[i],mod-2);
 }
}
int main()
{
   //freopen("input.txt","r",stdin);
   //freopen("out.txt","w",stdout);
   init();
   int t;
    cin>>t ;
    ll anser=0;
    while(t--)
    {
        anser=0;
        int n,k;
        cin >> n >> k;
        int now=n-k;
        if(now==0||now==1)
        {
        if(now==0)
        {
        printf("1\n");
        continue;
        }
        else
        {
        printf("0\n");
        continue;
        }
        }
        anser++;
        ll cur=0;
        for(int i=now;i>=2;i--)
        {
        anser+=(((jie[n]*ni[i]%mod)*ni[n-i]%mod)*cuo[i])%mod;
        }
        cout<<anser%mod<<endl;
    }
    return 0;
}

L:爆搜

#include<stdio.h>
#include<math.h>
#include<string.h>
#include<iostream>
#include<algorithm>
#define INF 2139062143
#define inf -2139062144
#define ll long long
using namespace std;
int qi[3][3];
bool flag;
int ini;
bool pan(int des) {
    if(qi[0][0] == qi[0][1] && qi[0][0] == qi[0][2] && qi[0][0] == des)    return true;
    if(qi[1][0] == qi[1][1] && qi[1][0] == qi[1][2] && qi[1][0] == des)    return true;
    if(qi[2][0] == qi[2][1] && qi[2][0] == qi[2][2] && qi[2][0] == des)    return true;

    if(qi[0][0] == qi[1][0] && qi[0][0] == qi[2][0] && qi[0][0] == des)    return true;
    if(qi[0][1] == qi[1][1] && qi[0][1] == qi[2][1] && qi[0][1] == des)    return true;
    if(qi[0][2] == qi[1][2] && qi[0][2] == qi[2][2] && qi[0][2] == des)    return true;

    if(qi[0][0] == qi[1][1] && qi[0][0] == qi[2][2] && qi[0][0] == des)    return true;
    if(qi[0][2] == qi[1][1] && qi[0][2] == qi[2][0] && qi[2][0] == des)    return true;
    return false;
}
bool dfs(int now,int step) {
    int i,j;
    if(step == 0) {
        if(pan(ini))    flag = true;
        for(i=0; i<3; i++) {
            for(j=0; j<3; j++) {
//                printf("fuck:%d %d %d\n",i,j,qi[i][j]);
                if(qi[i][j] == 0) {
                    qi[i][j] = ini;
                    if(pan(ini) == true)    flag = true;
                    if(dfs(now * (-1),1) == true)    flag = true;
                    qi[i][j] = 0;
                }
            }
        }
    } else {
        if(step == 1) {
            bool temp = true;
            for(i=0; i<3; i++) {
                for(j=0; j<3; j++) {
                    if(qi[i][j] == 0) {
                        qi[i][j] = (ini*-1);
                        if(pan(ini*-1))    temp = false;
                        if(dfs(ini,2) == false)    temp = false;
                        qi[i][j] = 0;
                    }
                }
            }
            return temp;
        } else {
            if(step == 2) {
                bool tt = false;
                for(i=0; i<3; i++) {
                    for(j=0; j<3; j++) {
                        if(qi[i][j] == 0) {
                            qi[i][j] = ini;
                            if(pan(ini))    tt = true;
                            qi[i][j] = 0;
                        }
                    }
                }
                return tt;
            }
        }
    }
}
int main() {
    int t;
    scanf("%d",&t);
    while(t--) {
        int i,j;
        getchar();
        for(i=0; i<3; i++) {
            for(j=0; j<3; j++) {
                char x[5];
                scanf("%s",x);
                char te = x[0];
                if(te == ‘.‘)    qi[i][j] = 0;
                if(te == ‘o‘)    qi[i][j] = 1;
                if(te == ‘x‘)    qi[i][j] = -1;
            }
        }

        char x[5];
        scanf("%s",x);
        char te = x[0];
        int now;
        if(te == ‘o‘)    now = 1;
        if(te == ‘x‘)    now = -1;
        ini = now;
        flag = false;

        if(pan(ini * -1) == true) {
            printf("Cannot win!\n");
        } else {
//            for(i=0; i<3; i++) {
//                for(j=0; j<3; j++)
//                    printf("%d ",qi[i][j]);
//                printf("\n");
//            }
            dfs(now,0);
            if(flag)    printf("Kim win!\n");
            else    printf("Cannot win!\n");
        }
    }
    return 0;
}

时间: 2024-10-27 07:41:48

Summer training round2 #1的相关文章

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 #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 10000000

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