zoukankan      html  css  js  c++  java
  • Codeforces Beta Round #32 (Div. 2, Codeforces format)

    Codeforces Beta Round #32 (Div. 2, Codeforces format)

    http://codeforces.com/contest/32

    A

     1 #include<bits/stdc++.h>
     2 using namespace std;
     3 #define lson l,mid,rt<<1
     4 #define rson mid+1,r,rt<<1|1
     5 #define sqr(x) ((x)*(x))
     6 #define pb push_back
     7 #define maxn 1000005
     8 typedef long long ll;
     9 typedef unsigned long long ull;
    10 /*#ifndef ONLINE_JUDGE
    11         freopen("1.txt","r",stdin);
    12 #endif */
    13 
    14 int n,m;
    15 int a[1005];
    16 
    17 int main(){
    18     #ifndef ONLINE_JUDGE
    19       //  freopen("1.txt","r",stdin);
    20     #endif
    21     std::ios::sync_with_stdio(false);
    22     cin>>n>>m;
    23     int ans=0;
    24     for(int i=1;i<=n;i++) cin>>a[i];
    25     for(int i=1;i<=n;i++){
    26         for(int j=1;j<=n;j++){
    27             if(i!=j&&abs(a[i]-a[j])<=m){
    28                 ans++;
    29             }
    30         }
    31     }
    32     cout<<ans<<endl;
    33 }
    View Code

    B

    模拟

     1 #include<bits/stdc++.h>
     2 using namespace std;
     3 #define lson l,mid,rt<<1
     4 #define rson mid+1,r,rt<<1|1
     5 #define sqr(x) ((x)*(x))
     6 #define pb push_back
     7 #define maxn 1000005
     8 typedef long long ll;
     9 typedef unsigned long long ull;
    10 /*#ifndef ONLINE_JUDGE
    11         freopen("1.txt","r",stdin);
    12 #endif */
    13 
    14 int n,m;
    15 int a[1005];
    16 
    17 int main(){
    18     #ifndef ONLINE_JUDGE
    19       //  freopen("1.txt","r",stdin);
    20     #endif
    21     std::ios::sync_with_stdio(false);
    22     string str;
    23     cin>>str;
    24     for(int i=0;i<str.length();i++){
    25         if(str[i]=='.'){
    26             cout<<0;
    27         }
    28         else{
    29             if(str[i+1]=='.'){
    30                 cout<<1;
    31             }
    32             else{
    33                 cout<<2;
    34             }
    35             i++;
    36         }
    37     }
    38 }
    View Code

    C

    水题

     1 #include<bits/stdc++.h>
     2 using namespace std;
     3 #define lson l,mid,rt<<1
     4 #define rson mid+1,r,rt<<1|1
     5 #define sqr(x) ((x)*(x))
     6 #define pb push_back
     7 #define maxn 1000005
     8 typedef long long ll;
     9 typedef unsigned long long ull;
    10 /*#ifndef ONLINE_JUDGE
    11         freopen("1.txt","r",stdin);
    12 #endif */
    13 
    14 
    15 int main(){
    16     #ifndef ONLINE_JUDGE
    17       //  freopen("1.txt","r",stdin);
    18     #endif
    19     std::ios::sync_with_stdio(false);
    20     ll n,m,s;
    21     cin >> n  >> m >> s;
    22     ll w = (n - 1) / s;
    23     ll h = (m - 1) / s;
    24     ll cnt = (w + 1) * (h + 1);
    25     ll a = min (s - 1 , (m - 1) % s);
    26     ll b = min (s - 1 , (n - 1) % s);
    27     cout << (a + 1) * (b + 1) * cnt << endl;
    28     return 0;
    29 }
    View Code

    D

    模拟

     1 #include<bits/stdc++.h>
     2 using namespace std;
     3 #define lson l,mid,rt<<1
     4 #define rson mid+1,r,rt<<1|1
     5 #define sqr(x) ((x)*(x))
     6 #define pb push_back
     7 #define maxn 1000005
     8 typedef long long ll;
     9 typedef unsigned long long ull;
    10 /*#ifndef ONLINE_JUDGE
    11         freopen("1.txt","r",stdin);
    12 #endif */
    13 
    14 string a[305];
    15 int n,m,k;
    16 int main(){
    17     #ifndef ONLINE_JUDGE
    18       //  freopen("1.txt","r",stdin);
    19     #endif
    20     std::ios::sync_with_stdio(false);
    21     cin>>n>>m>>k;
    22     for (int i=0;i<n;i++) cin>>a[i];
    23     for (int r=1;r<n;r++)
    24         for (int i=r;i<n-r;i++)
    25             for (int j=r;j<m-r;j++)
    26                 if (a[i][j]=='*'&&a[i+r][j]=='*'&&a[i][j+r]=='*'&&a[i-r][j]=='*'&&a[i][j-r]=='*'){
    27                     k--;
    28                     if (!k){
    29                         cout<<i+1<<" "<<j+1<<" "<<i-r+1<<" "<<j+1<<" "<<i+r+1<<" "<<j+1<<" "<<i+1<<" "<<j-r+1<<" "<<i+1<<" "<<j+r+1<<endl;
    30                         return 0;
    31                     }
    32                 }
    33     cout<<-1<<endl;
    34 }
    View Code

    E

    几何

    先判断AB是否可以直接相连,不能的话就做A对于镜面的对称点,连接对称点和B,判断这条线段和镜面是否有交点,再判断交点连A是否会经过墙,交点连B是否会经过墙

      1 #include<bits/stdc++.h>
      2 using namespace std;
      3 #define lson l,mid,rt<<1
      4 #define rson mid+1,r,rt<<1|1
      5 #define sqr(x) ((x)*(x))
      6 #define pb push_back
      7 #define eps 1e-8
      8 #define PI acos(-1.0)
      9 #define maxn 1000005
     10 typedef long long ll;
     11 typedef unsigned long long ull;
     12 
     13 /*#ifndef ONLINE_JUDGE
     14         freopen("1.txt","r",stdin);
     15 #endif */
     16 int sgn(double x){
     17     if(fabs(x)<eps) return 0;
     18     if(x<0) return -1;
     19     else return 1;
     20 }
     21 struct Point{
     22     double x,y;
     23     Point(){}
     24     Point(double _x,double _y){
     25         x=_x;
     26         y=_y;
     27     }
     28     void input(){
     29         scanf("%lf %lf",&x,&y);
     30     }
     31     void output(){
     32         printf("%.2f %.2f
    ",x,y);
     33     }
     34     bool operator == (const Point &b)const{
     35         return sgn(x-b.x) == 0 && sgn(y-b.y)== 0;
     36     }
     37     bool operator < (const Point &b)const{
     38         return sgn(x-b.x)==0?sgn(y-b.y)<0:x<b.x;
     39     }
     40     Point operator - (const Point &b)const{
     41         return Point(x-b.x,y-b.y);
     42     }
     43     //叉积
     44     double operator ^ (const Point &b)const{
     45         return x*b.y-y*b.x;
     46     }
     47     //点积
     48     double operator * (const Point &b)const{
     49         return x*b.x+y*b.y;
     50     }
     51     //返回长度
     52     double len(){
     53         return hypot(x,y);
     54     }
     55     //返回长度的平方
     56     double len2(){
     57         return x*x+y*y;
     58     }
     59     //返回两点的距离
     60     double distance(Point p){
     61         return hypot(x-p.x,y-p.y);
     62     }
     63     Point operator + (const Point &b)const{
     64         return Point(x+b.x,y+b.y);
     65     }
     66     Point operator * (const double &k)const{
     67         return Point(x*k,y*k);
     68     }
     69     Point operator / (const double &k)const{
     70         return Point(x/k,y/k);
     71     }
     72 
     73     //计算pa和pb的夹角
     74     //就是求这个点看a,b所成的夹角
     75     ///LightOJ1202
     76     double rad(Point a,Point b){
     77         Point p=*this;
     78         return fabs(atan2(fabs((a-p)^(b-p)),(a-p)*(b-p)));
     79     }
     80     //化为长度为r的向量
     81     Point trunc(double r){
     82         double l=len();
     83         if(!sgn(l)) return *this;
     84         r/=l;
     85         return Point(x*r,y*r);
     86     }
     87     //逆时针转90度
     88     Point rotleft(){
     89         return Point(-y,x);
     90     }
     91     //顺时针转90度
     92     Point rotright(){
     93         return Point(y,-x);
     94     }
     95     //绕着p点逆时针旋转angle
     96     Point rotate(Point p,double angle){
     97         Point v=(*this) -p;
     98         double c=cos(angle),s=sin(angle);
     99         return Point(p.x+v.x*c-v.y*s,p.y+v.x*s+v.y*c);
    100     }
    101 };
    102 
    103 struct Line{
    104     Point s,e;
    105     Line(){}
    106     Line(Point _s,Point _e){
    107         s=_s;
    108         e=_e;
    109     }
    110     bool operator==(Line v){
    111         return (s==v.s)&&(e==v.e);
    112     }
    113     //根据一个点和倾斜角angle确定直线,0<=angle<pi
    114     Line(Point p,double angle){
    115         s=p;
    116         if(sgn(angle-PI/2)==0){
    117             e=(s+Point(0,1));
    118         }
    119         else{
    120             e=(s+Point(1,tan(angle)));
    121         }
    122     }
    123     //ax+by+c=0;
    124     Line(double a,double b,double c){
    125         if(sgn(a)==0){
    126             s=Point(0,-c/b);
    127             e=Point(1,-c/b);
    128         }
    129         else if(sgn(b)==0){
    130             s=Point(-c/a,0);
    131             e=Point(-c/a,1);
    132         }
    133         else{
    134             s=Point(0,-c/b);
    135             e=Point(1,(-c-a)/b);
    136         }
    137     }
    138     void input(){
    139         s.input();
    140         e.input();
    141     }
    142     void adjust(){
    143         if(e<s) swap(s,e);
    144     }
    145     //求线段长度
    146     double length(){
    147         return s.distance(e);
    148     }
    149     inline double operator * (const Point &p) const {
    150         return (e - s) * (p - s);
    151     }
    152     //返回直线倾斜角 0<=angle<pi
    153     double angle(){
    154         double k=atan2(e.y-s.y,e.x-s.x);
    155         if(sgn(k)<0) k+=PI;
    156         if(sgn(k-PI)==0) k-=PI;
    157         return k;
    158     }
    159     //点和直线的关系
    160     //1 在左侧
    161     //2 在右侧
    162     //3 在直线上
    163     int relation(Point p){
    164         int c=sgn((p-s)^(e-s));
    165         if(c<0) return 1;
    166         else if(c>0) return 2;
    167         else return 3;
    168     }
    169     //点在线段上的判断
    170     bool pointonseg(Point p){
    171         return sgn((p-s)^(e-s))==0&&sgn((p-s)*(p-e))<=0;
    172     }
    173     //两向量平行(对应直线平行或重合)
    174     bool parallel(Line v){
    175       //  cout<<sgn((e-s)^(v.e-v.s))<<endl;
    176         return sgn((e-s)^(v.e-v.s))==0;
    177     }
    178     //两线段相交判断
    179     //2 规范相交
    180     //1 非规范相交
    181     //0 不相交
    182     int segcrossseg(Line v){
    183         int d1=sgn((e-s)^(v.s-s));
    184         int d2=sgn((e-s)^(v.e-s));
    185         int d3=sgn((v.e-v.s)^(s-v.s));
    186         int d4=sgn((v.e-v.s)^(e-v.s));
    187         if((d1^d2)==-2&&(d3^d4)==-2) return 2;
    188         return (d1==0&&sgn((v.s-s)*(v.s-e))<=0||
    189                 d2==0&&sgn((v.e-s)*(v.e-e))<=0||
    190                 d3==0&&sgn((s-v.s)*(s-v.e))<=0||
    191                 d4==0&&sgn((e-v.s)*(e-v.e))<=0);
    192     }
    193     //直线和线段相交判断
    194     //-*this line -v seg
    195     //2 规范相交
    196     //1 非规范相交
    197     //0 不相交
    198     int linecrossseg(Line v){
    199         int d1=sgn((e-s)^(v.s-s));
    200         int d2=sgn((e-s)^(v.e-s));
    201         if((d1^d2)==-2) return 2;
    202         return (d1==0||d2==0);
    203     }
    204     //两直线关系
    205     //0 平行
    206     //1 重合
    207     //2 相交
    208     int linecrossline(Line v){
    209         if((*this).parallel(v))
    210             return v.relation(s)==3;
    211         return 2;
    212     }
    213     //求两直线的交点
    214     //要保证两直线不平行或重合
    215     Point crosspoint(Line v){
    216         double a1=(v.e-v.s)^(s-v.s);
    217         double a2=(v.e-v.s)^(e-v.s);
    218         if(a1==a2) return Point(1e9,1e9);
    219         return Point((s.x*a2-e.x*a1)/(a2-a1),(s.y*a2-e.y*a1)/(a2-a1));
    220     }
    221     Point PointtoLine(const Point &p){
    222         return crosspoint(Line(p,p+(s-e).rotleft()));
    223     }
    224     Point SymPoint (const Point &p) {
    225         return PointtoLine (p) * 2 - p;
    226     }
    227     //点到直线的距离
    228     double dispointtoline(Point p){
    229         return fabs((p-s)^(e-s))/length();
    230     }
    231     //点到线段的距离
    232     double dispointtoseg(Point p){
    233         if(sgn((p-s)*(e-s))<0||sgn((p-e)*(s-e))<0)
    234             return min(p.distance(s),p.distance(e));
    235         return dispointtoline(p);
    236     }
    237     //返回线段到线段的距离
    238     //前提是两线段不相交,相交距离就是0了
    239     double dissegtoseg(Line v){
    240         return min(min(dispointtoseg(v.s),dispointtoseg(v.e)),min(v.dispointtoseg(s),v.dispointtoseg(e)));
    241     }
    242     //返回点P在直线上的投影
    243     Point lineprog(Point p){
    244         return s+(((e-s)*((e-s)*(p-s)))/((e-s).len2()));
    245     }
    246     //返回点P关于直线的对称点
    247     Point symmetrypoint(Point p){
    248         Point q=lineprog(p);
    249         return Point(2*q.x-p.x,2*q.y-p.y);
    250     }
    251 };
    252 ///两点之间,两点和镜子之间,镜子和墙
    253 int main(){
    254     #ifndef ONLINE_JUDGE
    255         freopen("1.txt","r",stdin);
    256     #endif
    257     std::ios::sync_with_stdio(false);
    258     Point v,p;
    259     v.input();
    260     p.input();
    261     Line w,m,L;
    262     w.input();
    263     m.input();
    264     L.s=v,L.e=p;
    265     if(L.segcrossseg(w)==0){
    266         if(L.segcrossseg(m)==0||L.parallel(m)){
    267             cout<<"YES"<<endl;
    268             return 0;
    269         }
    270     }
    271     else{
    272         Point tt=m.symmetrypoint(p);
    273         if(m.segcrossseg(Line(v,tt))!=0){
    274             Point pp=m.crosspoint(Line(v,tt));
    275             if(pp.x==1e9&&pp.y==1e9){
    276                 pp=p;
    277             }
    278             Line l1,l2;
    279             l1.s=v,l1.e=pp;
    280             l2.s=p,l2.e=pp;
    281            // cout<<l1.segcrossseg(w)<<" "<<l2.segcrossseg(w)<<endl;
    282             if(l1.segcrossseg(w)==0&&l2.segcrossseg(w)==0){
    283                 cout<<"YES"<<endl;
    284                 return 0;
    285             }
    286         }
    287     }
    288     cout<<"NO"<<endl;
    289     return 0;
    290 }
    View Code
  • 相关阅读:
    java中的多线程
    PSCollectionView瀑布流实现
    直接拿来用!最火的iOS开源项目(一~三)
    iOS6新特征:UICollectionView介绍
    mac os颜色拾取工具/软件/器推荐
    ios/object-c中的UIColor一些比较偏的颜色展示/示例
    UIColor和 同 CIColor 与 CGColor 之间的联系、转换
    IOS开发自定义CheckBox控件
    IOS常用的第三方开发库
    JVM -XX: 参数介绍
  • 原文地址:https://www.cnblogs.com/Fighting-sh/p/10389581.html
Copyright © 2011-2022 走看看