• 2014/5/25 多校


    A:

      1 #include<iostream>
      2 #include<stdio.h>
      3 #include<string.h>
      4 #include<set>
      5 #define maxn 5+8*300000
      6 using namespace std;
      7  
      8 set<int>S;
      9 int Enum=0,score[maxn],son[maxn][26],l[maxn];
     10 bool flag[maxn];//标记是否打星
     11 int tot_score,num,str_len;//个数
     12 char ans_string[15];
     13 char Map[5][5];
     14 bool vis[5][5];
     15 void init(){
     16     tot_score=0;num=0;str_len=0;
     17 }
     18 int newnode(){
     19     Enum++;
     20     memset(son[Enum],0,26*sizeof(son[Enum][0]));
     21     flag[Enum]=false;
     22     score[Enum]=0;
     23     l[Enum]=0;
     24     return Enum;
     25 }
     26 int cal_score(int len){
     27     if (len<=2) return 0;
     28     if (len<=4) return 1;
     29     if (len==5) return 2;
     30     if (len==6) return 3;
     31     if (len==7) return 5;
     32     if (len==8) return 11;
     33 }
     34 void Insert(char *str){
     35     int u=0,len=strlen(str);
     36     for(int i=0;i<len;i++){
     37         int id=str[i]-'A';
     38         if (son[u][id]==0){
     39             son[u][id]=newnode();
     40         }
     41         u=son[u][id];
     42     }
     43     //u是最底层,也代表当前结点
     44     score[u]=cal_score(len);
     45     flag[u]=true;
     46     l[u]=len;
     47 }
     48 int a[][2]={{1,0},{-1,0},{0,1},{0,-1},{1,1},{1,-1},{-1,1},{-1,-1}};
     49 char ss[20];
     50 void dfs(int id,int x,int y,int k){
     51  
     52     if (flag[id] && S.count(id)==0){
     53         num++;
     54         S.insert(id);
     55         tot_score+=score[id];
     56         ss[k]='';
     57         if (l[id]>str_len || (l[id]==str_len && strcmp(ss,ans_string)<0)){
     58             str_len=l[id];
     59             strcpy(ans_string,ss);
     60         }
     61     }
     62     for(int i=0;i<8;i++){
     63         int xx=x+a[i][0];
     64         int yy=y+a[i][1];
     65         if (xx<0 || yy<0 || xx>=4 || yy>=4) continue;
     66         int v=Map[xx][yy]-'A';
     67         if(son[id][v] && !vis[xx][yy]) {
     68             vis[xx][yy]=true;
     69             ss[k]=Map[xx][yy];
     70             dfs(son[id][v],xx,yy,k+1);
     71             vis[xx][yy]=false;
     72         }
     73     }
     74 }
     75 void solve(){
     76     for(int i=0;i<4;i++){
     77         for(int j=0;j<4;j++){
     78             int id=Map[i][j]-'A';
     79             if (son[0][id]>0){
     80                 vis[i][j]=true;
     81                 ss[0]=Map[i][j];
     82                 dfs(son[0][id],i,j,1);
     83                 vis[i][j]=false;
     84             }
     85         }
     86     }
     87     printf("%d %s %d
    ",tot_score,ans_string,num);
     88 }
     89 int main(){
     90     memset(son[0],0,sizeof(son[0]));
     91     int n;
     92     scanf("%d",&n);
     93     for(int i=0;i<n;i++){
     94         char s[20];
     95         scanf("%s",s);
     96         Insert(s);
     97     }
     98  
     99     int m;
    100     scanf("%d",&m);
    101  
    102     for(int cas=1;cas<=m;cas++){
    103         S.clear();init();
    104         memset(vis,0,sizeof(vis));
    105         for(int i=0;i<4;i++) scanf("%s",Map[i]);
    106         solve();
    107     }
    108     return 0;
    109 }
    View Code

    B:

     1 #include<iostream>
     2 #include<string.h>
     3 #include<stdio.h>
     4 #include<math.h>
     5 #include<queue>
     6 #include<algorithm>
     7 #include<vector>
     8 #define maxn 11000
     9 using namespace std;
    10  
    11 struct Node{
    12     int s;
    13     int type;//L点或者R点;
    14     bool operator<(const Node &X)const{
    15         if (X.s==s) return type>X.type;
    16         return s<X.s;
    17     }
    18 }node[maxn];
    19 int N,C,cnt;
    20 int y,m,d,h,s;
    21 char day[]={0,31,28,31,30,31,30,31,31,30,31,30,31};
    22 int cal_time(){
    23     int ans=0;
    24     ans+=(y-2013)*365*24*60;
    25     for(int i=1;i<=12;i++){
    26         if (i<m){
    27             if (i==2){
    28                 if (y==2016) ans+=29*24*60;else ans+=28*24*60;
    29             }else {
    30                 ans+=day[i]*24*60;
    31             }
    32         }else break;
    33     }
    34     ans+=(d-1)*24*60;
    35     ans+=h*60+s;
    36     return ans;
    37 }
    38 void read(){
    39     char s1[50];
    40     scanf("%s",s1);
    41     scanf("%d-%d-%d",&y,&m,&d);
    42     scanf("%d:%d",&h,&s);
    43     int t1=cal_time();
    44     node[cnt++]=(Node){t1,1};
    45     scanf("%d-%d-%d",&y,&m,&d);
    46     scanf("%d:%d",&h,&s);
    47     int t2=cal_time()+C;
    48     node[cnt++]=(Node){t2,2};
    49 }
    50 int solve(){
    51     int coun=0,ans=0;
    52     sort(node,node+cnt);
    53     for(int i=0;i<cnt;i++){
    54         if (node[i].type==1) ans=max(ans,++coun);
    55         else coun--;
    56     }
    57     return ans;
    58 }
    59 int main(){
    60 //    freopen("input.txt","r",stdin);
    61     int T;
    62     scanf("%d",&T);
    63     while(T--){
    64         scanf("%d%d",&N,&C);
    65         cnt=0;
    66         for(int i=0;i<N;i++){
    67              read();
    68         }
    69         printf("%d
    ",solve());
    70     }
    71     return 0;
    72 }
    View Code

    C:

     1 #include<iostream>
     2 #include<string.h>
     3 #include<stdio.h>
     4  
     5 using namespace std;
     6 int x1,y1,x2,y2;
     7 char c1,c2;
     8 int a[][2]={{1,-1},{1,1},{-1,1},{-1,-1}};
     9 void read(){
    10     char s[5];
    11     scanf("%s",s);
    12     c1=s[0];
    13     x1=8-(c1-'A');
    14     scanf("%s",s);
    15     y1=s[0]-'0';
    16     scanf("%s",s);
    17     c2=s[0];
    18     x2=8-(c2-'A');
    19     scanf("%s",s);
    20     y2=s[0]-'0';
    21     return ;
    22 }
    23 bool same(){
    24     if (x1==x2 && y1==y2) return true;else return false;
    25 }
    26 void solve(){
    27     bool ans=false;
    28     for(int i=0;i<4;i++){
    29         for(int j=1;j<=8;j++){
    30             int x=x1+a[i][0]*j;
    31             int y=y1+a[i][1]*j;
    32             if (!(x<=8 && x>=1 && y<=8 && y>=1)) break;
    33             if ((x1-x)*(x-x2)+(y1-y)*(y-y2)==0) {
    34                 ans=true;
    35                 printf("2 %c %d %c %d %c %d
    ",c1,y1,'A'+8-x,y,c2,y2);
    36                 break;
    37             }
    38         }
    39         if (ans) break;
    40     }
    41     return ;
    42 }
    43 int main(){
    44     int T;
    45     scanf("%d
    ",&T);
    46     while(T--){
    47         read();
    48         if ((x1+y1) % 2 != (x2+y2) % 2 ) {
    49             printf("Impossible
    ");
    50             continue;
    51         }
    52         if (same()){
    53             printf("%d %c %d
    ",0,c1,y1);
    54             continue;
    55         }
    56         int d1=x1-x2,d2=y1-y2;
    57         if (d1==d2){
    58             printf("%d %c %d %c %d
    ",1,c1,y1,c2,y2);
    59         }else solve();
    60     }
    61     return 0;
    62 }
    View Code

    D:

     1 #include<iostream>
     2 #include<string.h>
     3 #include<stdio.h>
     4 #include<math.h>
     5 #include<queue>
     6 #include<algorithm>
     7 #include<vector>
     8 using namespace std;
     9  
    10 vector<int> G[155];
    11 int N;
    12 int x[155],y[155];
    13 bool vis[155];
    14 bool bfs(){//找到一条从0到N+1点的通路
    15     memset(vis,0,sizeof(vis));
    16     vis[0]=0;
    17     queue<int>Q;
    18     Q.push(0);
    19     while(!Q.empty()){
    20         int u=Q.front();Q.pop();
    21         int cnt=G[u].size();
    22         for(int i=0;i<cnt;i++){
    23             int v=G[u][i];
    24             if (vis[v]) continue;
    25             vis[v]=true;
    26             Q.push(v);
    27         }
    28     }
    29     if (vis[N+1]) return true;else return false;
    30 }
    31 int main(){
    32     int t;
    33     scanf("%d",&t);
    34     while(t--){
    35         scanf("%d",&N);
    36         for(int i=0;i<=N+1;i++) G[i].clear();
    37         for(int i=0;i<=N+1;i++){
    38             scanf("%d%d",&x[i],&y[i]);
    39         }
    40         for(int i=0;i<=N+1;i++){
    41             for(int j=0;j<=N+1;j++){
    42                 if (i==j) continue;
    43                 if (abs(x[i]-x[j])+abs(y[i]-y[j])<=1000) {
    44                         G[i].push_back(j);
    45                 }
    46             }
    47         }
    48         if (bfs()) printf("happy
    ");else printf("sad
    ");
    49     }
    50     return 0;
    51 }
    View Code

    E:

     1 #include <iostream>
     2 #include <cstdio>
     3 #include <math.h>
     4 using namespace std;
     5  
     6 double A,B,H;
     7 double V;
     8 int N;
     9 double F(double x){
    10     double ans= A*exp(-x*x)+B*sqrt(x);
    11     return ans*ans*M_PI;
    12 }
    13 double simpson(double a,double b){
    14     double c=a+(b-a)/2;
    15     return (F(a)+4*F(c)+F(b))*(b-a)/6;
    16 }
    17 double asr(double a,double b,double eps,double AA,int deep){
    18     double c=a+(b-a)/2;
    19     double L=simpson(a,c),R=simpson(c,b);
    20     if (fabs(L+R-AA)<=15*eps && deep>=4) return L+R+(L+R-AA)/15.0;
    21     return asr(a,c,eps/2,L,deep+1)+asr(c,b,eps/2,R,deep+1);
    22 }
    23 double asr(double a,double b,double eps){
    24     return asr(a,b,eps,simpson(a,b),0);
    25 }
    26 double getans(){
    27     return asr(0,H,1e-10);
    28 }
    29 int main(){
    30     while(~scanf("%lf%d",&V,&N)){
    31         int ansp;
    32         double m=100000000;
    33         for(int i=1;i<=N;i++){
    34             scanf("%lf%lf%lf",&A,&B,&H);
    35             double ans=getans();
    36             double ab=fabs(V-ans);
    37             if (ab<m){
    38                 ansp=i-1;
    39                 m=ab;
    40             }
    41         }
    42         cout<<ansp<<endl;
    43     }
    44     return 0;
    45 }
    46  
    47 /**************************************************************
    48     Problem: 1461
    49     User: csu_newday
    50     Language: C++
    51     Result: Accepted
    52     Time:20 ms
    53     Memory:1496 kb
    54 ****************************************************************/
    View Code

    F:

     1 #include<iostream>
     2 #include<string.h>
     3 #include<stdio.h>
     4 #include<math.h>
     5 #include<queue>
     6 #include<algorithm>
     7 #include<vector>
     8 #define maxn 11000
     9 using namespace std;
    10  
    11 int a[][2]={{1,0},{-1,0},{0,1},{0,-1}};
    12 char Map[6][12];
    13 int ans,num;//答案,原来跳棋数
    14 void read(){
    15     num=0;
    16     for(int i=0;i<5;i++){
    17         scanf("%s",Map[i]);
    18         int len=strlen(Map[i]);
    19         for(int j=0;j<len;j++)
    20         if (Map[i][j]=='o') num++;
    21     }
    22     return;
    23 }
    24 void dfs(){
    25 //    for(int i=0;i<5;i++){
    26 //        for(int j=0;j<9;j++) cout<<Map[i][j];
    27 //        cout<<endl;
    28 //    }
    29     bool still=false;
    30     for(int x=0;x<5;x++){
    31         for(int y=0;y<9;y++){
    32             if (Map[x][y]=='o'){
    33                 for(int i=0;i<4;i++){
    34                     int x1=x+a[i][0];
    35                     int y1=y+a[i][1];
    36                     int x2=x+2*a[i][0];
    37                     int y2=y+2*a[i][1];
    38                     if (x1<0 || y1<0 || x1>=5 || y1>=9) continue;
    39                     if (x2<0 || y2<0 || x2>=5 || y2>=9) continue;
    40                     if (Map[x1][y1]=='o' && Map[x2][y2]=='.'){
    41                         still=true;
    42                         Map[x1][y1]='.';Map[x2][y2]='o';Map[x][y]='.';
    43                         dfs();
    44                         Map[x1][y1]='o';Map[x2][y2]='.';Map[x][y]='o';
    45                     }
    46                 }
    47             }
    48         }
    49     }
    50     if (!still){
    51         int coun=0;
    52         for(int i=0;i<5;i++){
    53             for(int j=0;j<9;j++){
    54                 if(Map[i][j]=='o') coun++;
    55             }
    56         }
    57         ans=min(ans,coun);
    58     }
    59     return ;
    60 }
    61 void solve(){
    62     ans=10000;
    63     dfs();
    64 }
    65 int main(){
    66 //    freopen("input.txt","r",stdin);
    67     int t;
    68     scanf("%d",&t);
    69     while(t--){
    70         read();
    71         solve();
    72         printf("%d %d
    ",ans,num-ans);//每次必然消去一个,所以有直接关联关系
    73     }
    74     return 0;
    75 }
    View Code

    G

    H

    I

    J

    K:

     1 #include <iostream>
     2 #include <math.h>
     3 #include <string.h>
     4 #include <stdio.h>
     5 #define eps 1e-7
     6 using namespace std;
     7 int dcmp(double x){
     8     if (fabs(x)<eps) return 0;
     9     if (x>eps) return 1;
    10     else return -1;
    11 }
    12 struct Point3{
    13     double x,y,z;
    14 };
    15 typedef Point3 Vector3;
    16 Vector3 operator-(Vector3 A,Vector3 B){
    17     return (Vector3){A.x-B.x,A.y-B.y,A.z-B.z};
    18 }
    19 Vector3 operator+(Vector3 A,Vector3 B){
    20     return (Vector3){A.x+B.x,A.y+B.y,A.z+B.z};
    21 }
    22 Vector3 operator*(Vector3 A,double p){
    23     return (Vector3){A.x*p,A.y*p,A.z*p};
    24 }
    25 double Dot(Vector3 A,Vector3 B){
    26     return A.x*B.x+A.y*B.y+A.z*B.z;
    27 }
    28 double Length(Vector3 A){
    29     return sqrt(Dot(A,A));
    30 }
    31 Vector3 Cross(Vector3 A,Vector3 B){
    32     return (Vector3){A.y*B.z-A.z*B.y,A.z*B.x-A.x*B.z,A.x*B.y-A.y*B.x};
    33 }
    34 double Area2(Point3 A,Point3 B,Point3 C){
    35     return Length(Cross(B-A,C-A));
    36 }
    37 bool PointInTri(Point3 P,Point3 P0,Point3 P1,Point3 P2){
    38     double a1=Area2(P,P0,P1);
    39     double a2=Area2(P,P1,P2);
    40     double a3=Area2(P,P2,P0);
    41     if (dcmp(a1)==0 || dcmp(a2)==0 || dcmp(a3)==0) return false;
    42     return dcmp(a1+a2+a3-Area2(P0,P1,P2))==0;
    43 }
    44 bool TriSegInter(Point3 P0,Point3 P1,Point3 P2,Point3 A,Point3 B){
    45     Vector3 n=Cross(P1-P0,P2-P0);
    46     if (dcmp(Dot(n,B-A))==0) return false;
    47     else {
    48         double t=Dot(n,P0-A)/Dot(n,B-A);
    49         if (dcmp(t)<0 || dcmp(t-1)>0) return false;
    50         Point3 P=A+(B-A)*t;
    51         return PointInTri(P,P0,P1,P2);
    52     }
    53 }
    54 Point3 p[10];
    55 int T;
    56 int main(){
    57     while(cin>>T){
    58         for(int cas=1;cas<=T;cas++){
    59             bool ans=false;
    60             for(int i=1;i<=6;i++){
    61             scanf("%lf%lf%lf",&p[i].x,&p[i].y,&p[i].z);
    62             }
    63             int t1=0,t2=0;
    64             if (TriSegInter(p[4],p[5],p[6],p[1],p[2])) t1++;
    65             if (TriSegInter(p[4],p[5],p[6],p[1],p[3])) t1++;
    66             if (TriSegInter(p[4],p[5],p[6],p[2],p[3])) t1++;
    67             if (TriSegInter(p[1],p[2],p[3],p[4],p[5])) t2++;
    68             if (TriSegInter(p[1],p[2],p[3],p[5],p[6])) t2++;
    69             if (TriSegInter(p[1],p[2],p[3],p[4],p[6])) t2++;
    70             if (t1==1 || t2==1) ans=true;
    71             if (ans) printf("YES
    ");else printf("NO
    ");
    72         }
    73     }
    74     return 0;
    75 }
    76  
    77 /**************************************************************
    78     Problem: 1467
    79     User: csu_newday
    80     Language: C++
    81     Result: Accepted
    82     Time:8 ms
    83     Memory:1500 kb
    84 ****************************************************************/
    View Code

     比赛总结:

     1 2014/5/25 多校比赛总结
     2 Little_W
     3 综述:这次比赛较简单,算法覆盖面较大,平均每道题的难度不大。前期出题较稳定,没什么卡题的,电脑基本也没歇着。这说明什么呢?我们的水平还是比较擅长中等的题。
     4 
     5 A:字典树维护+图上dfs搜索。很容易想到暴力的方法,但是稍微算一下复杂度,就知道不可行。所以就想到要用数据结构优化查找搜索范围的复杂度。编码较复杂,容易写错。比赛时我估计编码会出错,所以让队友来敲了。
     6 
     7 B:年份数据预处理+扫描出时间点穿过的最大区间(大白书上原有模型)当时注意了一下是2012--2016保证预处理成分钟一定不超long long就没什么问题了。扫描部分只有O(nlgn+n)不是很高。因为时间预处理容易出错,队友接手了这个题。当时这样安排是对的,让我有时间去思考别的题目。
     8 
     9 C:找到必然策略(机智题)。首先黑白染色的棋盘让我想到了一个有趣的游戏(证明能否对角线移动到),这个是奇偶剪枝的特例了。之后证明最多两步,必然能移动。沿对角线移动的过程,暴力枚举即可。
    10 
    11 D:预处理无向图+找面点间通路存在性。用简单证明可知1000以内距离即可连边。找通路存在性,可以BFS不断扩展边。去年写这个的时候,用的是Floyd的性质:就是一遍Floyd后就能判任意点对间的联通与否,把边表示成bool即可。但是后者较暴力。
    12 
    13 E:简单的积分运算题,运用微分的思想,变换一下公式即可。要是求绕y轴旋转,求反函数再积分即可。
    14 
    15 F:跳棋。暴力搜索题?我手动算计复杂度上限,觉得暴力不可做。幸好队友试了一下,DFS记录最大值,A了。不过后来想想,好像很难再对算法优化了。后来写了个更暴力的,都A了,更加不怎么明白为什么不会超时?
    16 
    17 G:贪心(wait)
    18 
    19 H:wait 题还没看懂
    20 
    21 I:。。。
    22 
    23 J:待补充
    24 
    25 K:三维几何+暴力枚举所有情况(判断每条边是否穿过一个三角形的面)。当时题目没看明白,看数据猜测的。判断线面交大白书上有模板。注意,两条线穿过,说明是没有套上的,三条线穿过是不可能的。事后想到如果判断一条直线和空间中凸多边形相交怎么做?答案是把凸多边形按照边的顺序分成N-2个小三角形,枚举判断即可,记住和某一小三角行相交是也可能在面内(比如和切割边相交),简单想了一下, 即使凸多边形是异面的,这个方法也是正确的。
    View Code
  • 相关阅读:
    Mybatis传入list的注意点
    synchronized锁
    手撸红黑树
    Vue cdn加速配置
    多线程之BlockingQueue中 take、offer、put、add的一些比较
    线程池
    ThreadLocal
    jdk LocalDateTime mybatis 空指针解决办法
    不同对象中 类型与属性名的属性 进行数据转换
    HashMap 的put方法
  • 原文地址:https://www.cnblogs.com/little-w/p/3751165.html
Copyright © 2020-2023  润新知