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