zoukankan      html  css  js  c++  java
  • codeforces--279--

    还是太弱啊 终测 C D都挂了 =_=

    ...porker写的C关于取模的运用 对于以后的题目 都有很好的 移植性  感觉主要是运用了 (a+b)%p = ( a%p+b%p)%p这个性质

    贴下 3题代码 当时比赛的时候 可能有点难看 懒的改了

     1 #include <cstdio>
     2 #include <vector>
     3 #include <algorithm>
     4 using namespace std;
     5 
     6 vector<int>ve[4];
     7 int a[10];
     8 
     9 int main()
    10 {
    11     int n , x , y , z , num;
    12     while( ~scanf("%d",&n) )
    13     {
    14         for( int i = 0 ; i<=3 ; i++ )
    15             ve[i].clear();
    16         for( int i = 1 ; i<=n ; i++ )
    17         {
    18             scanf("%d",&num);
    19             ve[ num ].push_back( i );
    20         }
    21         x = ve[1].size();
    22         y = ve[2].size();
    23         z = ve[3].size();
    24         a[0] = x;
    25         a[1] = y;
    26         a[2] = z;
    27         sort( a , a+3 );
    28         if( a[0]==0 )
    29             printf( "0
    " );
    30         else
    31         {
    32             printf( "%d
    ",a[0] );
    33             for( int i = 0 ; i<a[0] ; i++ )
    34             {
    35                 printf( "%d %d %d
    ",ve[1][i],ve[2][i],ve[3][i] );
    36             }
    37         }
    38     }
    39     return 0;
    40 }
    View Code

    B其实也蛮有意思的 先要 Hash找出队首 队尾元素 其实找一个就够了 他们出现的特点就是 只出现了1次 然后通过队首元素与第二个位置的元素的与其后继元素的Next关系

    进行不断遍历 然后最后输出就可以了

     1 #include <cstdio>
     2 #include <cstring>
     3 using namespace std;
     4 
     5 const int size = 1000010;
     6 int hash[size] , next[size] , pre[size];
     7 int ans[size];
     8 
     9 int main()
    10 {
    11     int n , x , y , cnt , first , last;
    12     while( ~scanf("%d",&n) )
    13     {
    14         memset( hash , 0 , sizeof(hash) );
    15         cnt = 0;
    16         for( int i = 1 ; i<=n ; i++ )
    17         {
    18             scanf( "%d %d",&x,&y );
    19             hash[x] ++;
    20             hash[y] --;
    21             next[x] = y;
    22             pre[y] = x;
    23         }
    24         for( int i = 1 ; i<=size ; i++ )
    25         {
    26             if( hash[i]==1 )
    27             {
    28                 ++ cnt;
    29                 first = i;
    30                 ans[1] = first;
    31             }
    32             else if( hash[i]==-1 )
    33             {
    34                 ++ cnt;
    35                 last = i;
    36                 ans[n] = last;
    37             }
    38             if( cnt==2 )
    39                 break;
    40         }
    41         ans[2] = next[0];
    42         ans[n-1] = pre[0];
    43         int u = ans[1];
    44         int v = ans[2];
    45         int t = 3;
    46         int k = 4;
    47         bool flag = true;
    48         while(1)
    49         {
    50             if( hash[ next[u] ]!=0 )
    51             {
    52                 flag = false;
    53             }
    54             else
    55             {
    56                 ans[t] = next[u];
    57                 t += 2;
    58                 u = next[u];
    59             }
    60             if( hash[ next[v] ]!=0 )
    61             {
    62                 flag = false;
    63             }
    64             else
    65             {
    66                 ans[k] = next[v];
    67                 k += 2;
    68                 v = next[v];
    69             }
    70             if( !flag )
    71                 break;
    72         }
    73         for( int i = 1 ; i<=n-1 ; i++ )
    74         {
    75             printf("%d ",ans[i] );
    76         }
    77         printf("%d
    ",ans[n]);
    78     }
    79     return 0;
    80 }
    View Code
     1 #include <iostream>
     2 #include <string>
     3 using namespace std;
     4 
     5 bool result[1000010];
     6 
     7 int main() {
     8     string s;
     9     bool flag;
    10     cin >> s;
    11     long long a, b;
    12     cin >> a >> b;
    13     long long temp = 1;
    14     long long temp2 = 0;
    15     flag = true;
    16     for ( int i = s.size() - 1; i > 0; i--) {
    17         temp %= b;
    18         temp2 += temp * ( s[i] - '0' );
    19         temp2 %= b;
    20         temp *= 10;
    21         if ( temp2 == 0 && s[i] != '0' ) {
    22             result[i] = true;
    23         }
    24         else {
    25             result[i] = false;
    26         }
    27     }
    28     temp2 = 0;
    29     for (int i = 0; i < s.size()-1; i++) {
    30         temp2 *= 10;
    31         temp2 += s[i] - '0';
    32         temp2 %= a;
    33         if (temp2 == 0 && result[i + 1]) {
    34             flag = false;
    35             cout << "YES" << endl;
    36             for (int j = 0; j <= i; j++) {
    37                 cout << s[j];
    38             }
    39             cout << endl;
    40             for (int j = i + 1; j < s.size(); j++) {
    41                 cout << s[j];
    42             }
    43             cout << endl;
    44             break;
    45         }
    46     }
    47     if( flag )
    48         cout << "NO" << endl;
    49 }
    View Code
  • 相关阅读:
    免费 官方的ASP.NET MVC电子书Professional ASP.NET MVC 1.0
    首次接觸 ADO.NET Entity Framework
    WaitAll for multiple handles on a STA thread is not supported. (原)
    太棒了!想学英语的好好留着!
    How should I Install SQL Server 2008 Express Edition
    How to view the W3WP process by c#?
    WinDbg basics HOWTO for QA engineers
    IIS Appcmd Tool
    Remote IIS Debugging : Debug your ASP.NET Application which is hosted on "Remote IIS Server"
    How to Set Up SSL on IIS 7
  • 原文地址:https://www.cnblogs.com/radical/p/4118824.html
Copyright © 2011-2022 走看看