목차
Solution 2:
웹 프론트엔드 HTML 튜토리얼 Codeforces Round #277 (Div. 2) 题解_html/css_WEB-ITnose

Codeforces Round #277 (Div. 2) 题解_html/css_WEB-ITnose

Jun 24, 2016 am 11:54 AM



Codeforces Round #277 (Div. 2)

A. Calculating Function

time limit per test

1 second

memory limit per test

256 megabytes

input

standard input

output

standard output

For a positive integer n let's define a function f:

f(n)?=??-?1?+?2?-?3?+?..?+?(?-?1)nn

Your task is to calculate f(n) for a given integer n.

Input

The single line contains the positive integer n (1?≤?n?≤?1015).

Output

Print f(n) in a single line.

Sample test(s)

input

output

input

output

-3
로그인 후 복사

Note

f(4)?=??-?1?+?2?-?3?+?4?=?2

f(5)?=??-?1?+?2?-?3?+?4?-?5?=??-?3

简单公式:

#include <iostream>#include <cstdio>#include <cstring>#include <algorithm>#include <cmath>using namespace std;typedef long long int LL;LL n;int main(){    cin>>n;    if(n%2==0)    {        LL t=n/2;        cout       <br>       <br>       <p></p>                      <p class="sycode">   </p>
<p class="sycode">    </p>
<p class="sycode">     </p>
<p class="sycode">      </p>
<p class="sycode">       </p>
<p class="sycode">        B. OR in Matrix       </p>       <p class="sycode">        </p>
<p class="sycode">         time limit per test        </p> 1 second              <p class="sycode">        </p>
<p class="sycode">         memory limit per test        </p> 256 megabytes              <p class="sycode">        </p>
<p class="sycode">         input        </p> standard input              <p class="sycode">        </p>
<p class="sycode">         output        </p> standard output                   <p class="sycode">       </p>
<p> Let's define logical OR as an operation on two logical values (i. e. values that belong to the set {0,?1}) that is equal to 1 if either or both of the logical values is set to 1, otherwise it is 0. We can define logical OR of three or more logical values in the same manner:</p>       <p>  where  is equal to 1 if some ai?=?1, otherwise it is equal to 0.</p>       <p> Nam has a matrix A consisting of m rows and n columns. The rows are numbered from 1 to m, columns are numbered from 1 to n. Element at row i(1?≤?i?≤?m) and column j (1?≤?j?≤?n) is denoted as Aij. All elements of A are either 0 or 1. From matrix A, Nam creates another matrix B of the same size using formula:</p>       <p> .</p>       <p> (Bij is OR of all elements in row i and column j of matrix A)</p>       <p> Nam gives you matrix B and challenges you to guess matrix A. Although Nam is smart, he could probably make a mistake while calculating matrix B, since size of A can be large.</p>            <p class="sycode">       </p>
<p class="sycode">        Input       </p>       <p> The first line contains two integer m and n (1?≤?m,?n?≤?100), number of rows and number of columns of matrices respectively.</p>       <p> The next m lines each contain n integers separated by spaces describing rows of matrix B (each element of B is either 0 or 1).</p>            <p class="sycode">       </p>
<p class="sycode">        Output       </p>       <p> In the first line, print "NO" if Nam has made a mistake when calculating B, otherwise print "YES". If the first line is "YES", then also print m rows consisting of n integers representing matrix A that can produce given matrix B. If there are several solutions print any one.</p>            <p class="sycode">       </p>
<p class="sycode">        Sample test(s)       </p>       <p class="sycode">        </p>
<p class="sycode">         </p>
<p class="sycode">          input         </p>         <pre style="代码" class="precsshei">2 21 00 0
로그인 후 복사

output

NO
로그인 후 복사

input

2 31 1 11 1 1
로그인 후 복사

output

YES1 1 11 1 1
로그인 후 복사

input

2 30 1 01 1 1
로그인 후 복사

output

YES0 0 00 1 0
로그인 후 복사

水题:将A里所有可能是1的点加上就可以了

#include <iostream>#include <cstdio>#include <cstring>#include <algorithm>using namespace std;int n,m;int B[220][220];int A[220][220];bool vis[220][220];bool check(int x,int y){    bool flag=true;    for(int i=0;i<m if flag="false;" for i="0;i<n&&flag;i++)" return cl x y vis main cin>>n>>m;    for(int i=0;i<n for j="0;j<m;j++)" cin>>B[i][j];    for(int i=0;i<n for j="0;j<m;j++)" if a cl bool flag="true;" i="0;i<n&&flag;i++)" puts cout else return>        <br>        <br>              <p class="sycode">        <br>       </p>       <p class="sycode">        C. Palindrome Transformation       </p>       <p class="sycode">        </p>
<p class="sycode">         time limit per test        </p> 1 second              <p class="sycode">        </p>
<p class="sycode">         memory limit per test        </p> 256 megabytes              <p class="sycode">        </p>
<p class="sycode">         input        </p> standard input              <p class="sycode">        </p>
<p class="sycode">         output        </p> standard output                   <p class="sycode">       </p>
<p> Nam is playing with a string on his computer. The string consists of n lowercase English letters. It is meaningless, so Nam decided to make the string more beautiful, that is to make it be a palindrome by using 4 arrow keys: left, right, up, down.</p>       <p> There is a cursor pointing at some symbol of the string. Suppose that cursor is at position i (1?≤?i?≤?n, the string uses 1-based indexing) now. Left and right arrow keys are used to move cursor around the string. The string is cyclic, that means that when Nam presses left arrow key, the cursor will move to position i?-?1 if i?>?1 or to the end of the string (i. e. position n) otherwise. The same holds when he presses the right arrow key (if i?=?n, the cursor appears at the beginning of the string).</p>       <p> When Nam presses up arrow key, the letter which the text cursor is pointing to will change to the next letter in English alphabet (assuming that alphabet is also cyclic, i. e. after 'z' follows 'a'). The same holds when he presses the down arrow key.</p>       <p> Initially, the text cursor is at position p.</p>       <p> Because Nam has a lot homework to do, he wants to complete this as fast as possible. Can you help him by calculating the minimum number of arrow keys presses to make the string to be a palindrome?</p>            <p class="sycode">       </p>
<p class="sycode">        Input       </p>       <p> The first line contains two space-separated integers n (1?≤?n?≤?105) and p (1?≤?p?≤?n), the length of Nam's string and the initial position of the text cursor.</p>       <p> The next line contains n lowercase characters of Nam's string.</p>            <p class="sycode">       </p>
<p class="sycode">        Output       </p>       <p> Print the minimum number of presses needed to change string into a palindrome.</p>            <p class="sycode">       </p>
<p class="sycode">        Sample test(s)       </p>       <p class="sycode">        </p>
<p class="sycode">         </p>
<p class="sycode">          input         </p>         <pre style="代码" class="precsshei">8 3aeabcaez
로그인 후 복사

output

Note

A string is a palindrome if it reads the same forward or reversed.

In the sample test, initial Nam's string is:  (cursor position is shown bold).

In optimal solution, Nam may do 6 following steps:

The result, , is now a palindrome.


因为没有删除操作,最后的回文串是什么样已经是确定的了, A-->A'  或 A'--->A 或到A和A'的中间值上下移动的次数是一样的,所以没有必要跨越中点

只要计算出在一边的左右移动次数就可以了....

#include <iostream>#include <cstdio>#include <cstring>#include <algorithm>#include <cmath>using namespace std;const int maxn=200100;const int INF=0x3f3f3f3f;char str[maxn];char rstr[maxn];int n,p;int change[maxn][2];void getC(){    for(int i=0;i<n a> A'        change[i][0]=max(str[i],rstr[i])-min(str[i],rstr[i]);        change[i][0]=min(change[i][0],min(str[i],rstr[i])+26-max(str[i],rstr[i]));        /// 1: A --> m >n>>p;    p--;    cin>>str;    int tt=n/2;    if(n%2==0) tt--;    if(p>tt)    {        reverse(str,str+n);        p=n-1-p;    }    memcpy(rstr,str,sizeof(str));    reverse(rstr,rstr+n);    getC();    int temp=0;    ///改变字符的花费    for(int i=0;i=0;i--)    {        if(change[i][0]!=0)        {            R=i; break;        }    }    int L=-1;    for(int i=0;i R        if(p>=L&&pR)        {            cout       <br>       <br>       <p></p>       <p> <br> </p>                      <p class="sycode">   </p>
<p class="sycode">    </p>
<p class="sycode">     </p>
<p class="sycode">      </p>
<p class="sycode">       </p>
<p class="sycode">        D. Valid Sets       </p>       <p class="sycode">        </p>
<p class="sycode">         time limit per test        </p> 1 second              <p class="sycode">        </p>
<p class="sycode">         memory limit per test        </p> 256 megabytes              <p class="sycode">        </p>
<p class="sycode">         input        </p> standard input              <p class="sycode">        </p>
<p class="sycode">         output        </p> standard output                   <p class="sycode">       </p>
<p> As you know, an undirected connected graph with n nodes and n?-?1 edges is called a tree. You are given an integer d and a tree consisting of nnodes. Each node i has a value ai associated with it.</p>       <p> We call a set S of tree nodes valid if following conditions are satisfied:</p>       <ol>        <li> S is non-empty.</li>        <li> S is connected. In other words, if nodes u and v are in S, then all nodes lying on the simple path between u and v should also be presented in S.</li>        <li> .</li>       </ol>       <p> Your task is to count the number of valid sets. Since the result can be very large, you must print its remainder modulo 1000000007 (109?+?7).</p>            <p class="sycode">       </p>
<p class="sycode">        Input       </p>       <p> The first line contains two space-separated integers d (0?≤?d?≤?2000) and n (1?≤?n?≤?2000).</p>       <p> The second line contains n space-separated positive integers a1,?a2,?...,?an(1?≤?ai?≤?2000).</p>       <p> Then the next n?-?1 line each contain pair of integers u and v (1?≤?u,?v?≤?n) denoting that there is an edge between u and v. It is guaranteed that these edges form a tree.</p>            <p class="sycode">       </p>
<p class="sycode">        Output       </p>       <p> Print the number of valid sets modulo 1000000007.</p>            <p class="sycode">       </p>
<p class="sycode">        Sample test(s)       </p>       <p class="sycode">        </p>
<p class="sycode">         </p>
<p class="sycode">          input         </p>         <pre style="代码" class="precsshei">1 42 1 3 21 21 33 4
로그인 후 복사

output

input

0 31 2 31 22 3
로그인 후 복사

output

input

4 87 8 7 5 4 6 4 101 61 25 81 33 56 73 4
로그인 후 복사

output

41
로그인 후 복사

Note

In the first sample, there are exactly 8 valid sets: {1},?{2},?{3},?{4},?{1,?2},?{1,?3},?{3,?4} and {1,?3,?4}. Set {1,?2,?3,?4} is not valid, because the third condition isn't satisfied. Set {1,?4} satisfies the third condition, but conflicts with the second condition.


树型DP,从每一个节点走只扩展和根节点 root  权值 在 root

如果扩展到某个节点 w[v]==w[root]   则标记一下,不要重复走

#include <iostream>#include <cstring>#include <cstdio>#include <algorithm>#include <vector>using namespace std;typedef long long int LL;const int maxn=2222;const LL mod=1000000007;int n,d,root;LL w[maxn];vector<int> g[maxn];bool vis[maxn][maxn];LL dp[maxn];LL dfs(int u,int fa){    dp[u]=1;    for(int i=0,sz=g[u].size();i<sz int v="g[u][i];" if continue vis temp="dfs(v,u);" dp return main cin>>d>>n;    for(int i=1; i>w[i];    for(int i=0; i<n-1 i int a cin>>a>>b;        g[a].push_back(b);        g[b].push_back(a);    }    LL sum=0;    for(int i=1; i        <br>        <br>              <p class="sycode">        E. LIS of Sequence       </p>       <p class="sycode">        </p>
<p class="sycode">         time limit per test        </p> 2 seconds              <p class="sycode">        </p>
<p class="sycode">         memory limit per test        </p> 256 megabytes              <p class="sycode">        </p>
<p class="sycode">         input        </p> standard input              <p class="sycode">        </p>
<p class="sycode">         output        </p> standard output                   <p class="sycode">       </p>
<p> The next "Data Structures and Algorithms" lesson will be about Longest Increasing Subsequence (LIS for short) of a sequence. For better understanding, Nam decided to learn it a few days before the lesson.</p>       <p> Nam created a sequence a consisting of n (1?≤?n?≤?105) elements a1,?a2,?...,?an (1?≤?ai?≤?105). A subsequence ai1,?ai2,?...,?aik where 1?≤?i1?<?i2 ?<?...?<?ik?≤?n is called increasing if ai1?<?ai2?<?ai3?<?...?<?aik. An increasing subsequence is called longest if it has maximum length among all increasing subsequences.</p>       </p>
<p> Nam realizes that a sequence may have several longest increasing subsequences. Hence, he divides all indexes i (1?≤?i?≤?n), into three groups:</p>       <ol>        <li> group of all i such that ai belongs to no longest increasing subsequences.</li>        <li> group of all i such that ai belongs to at least one but not every longest increasing subsequence.</li>        <li> group of all i such that ai belongs to every longest increasing subsequence.</li>       </ol>       <p> Since the number of longest increasing subsequences of a may be very large, categorizing process is very difficult. Your task is to help him finish this job.</p>            <p class="sycode">       </p>
<p class="sycode">        Input       </p>       <p> The first line contains the single integer n (1?≤?n?≤?105) denoting the number of elements of sequence a.</p>       <p> The second line contains n space-separated integers a1,?a2,?...,?an (1?≤?ai?≤?105).</p>            <p class="sycode">       </p>
<p class="sycode">        Output       </p>       <p> Print a string consisting of n characters. i-th character should be '1', '2' or '3' depending on which group among listed above index i belongs to.</p>            <p class="sycode">       </p>
<p class="sycode">        Sample test(s)       </p>       <p class="sycode">        </p>
<p class="sycode">         </p>
<p class="sycode">          input         </p>         <pre style="代码" class="precsshei">14
로그인 후 복사

output

input

41 3 2 5
로그인 후 복사

output

3223
로그인 후 복사

input

41 5 2 3
로그인 후 복사

output

3133
로그인 후 복사

Note

In the second sample, sequence a consists of 4 elements: {a1,?a2,?a3,?a4} = {1,?3,?2,?5}. Sequence a has exactly 2 longest increasing subsequences of length 3, they are {a1,?a2,?a4} = {1,?3,?5} and {a1,?a3,?a4} = {1,?2,?5}.

In the third sample, sequence a consists of 4 elements: {a1,?a2,?a3,?a4} = {1,?5,?2,?3}. Sequence a have exactly 1 longest increasing subsequence of length 3, that is {a1,?a3,?a4} = {1,?2,?3}.



Solution 2:

// Some notation is re-defined.

  • Let F1i be the length of LIS ending exactly at ai of sequence {a1,?a2,?...,?ai}.

  • Let F2i be the length of LIS beginning exactly at ai of sequence {ai,?ai?+?1,?...,?an}.

  • l = length of LIS of {a1,?a2,?...,?an} = max{F1i} = max{F2j}.

  • Let Fi be the length of LIS of sequence {a1,?a2,?...,?ai?-?1,?ai?+?1,?...,?an} (i.e the length of LIS of initial sequence a after removing element ai).

  • Index i must in group:

    1) if F1i?+?F2i?-?1?

    2) if Fi?=?l

    3) if Fi?=?l?-?1

  • How to caculate Fi? We have: Fi?=?max{F1u?+?F2v} among 1?≤?u?


  • 正反求两遍LIS,比较一下即可.....


    如果F1[i]+F2[j]-1==LIS 要用map记录下有没有相同的F1[i],F2[i]   有输出2 没有输出3


    #include <iostream>#include <cstdio>#include <cstring>#include <algorithm>#include <vector>#include <set>#include <map>using namespace std;const int maxn=100100;int n,a[maxn],b[maxn];int f1[maxn],f2[maxn];int v1[maxn],n1,v2[maxn],n2;set<int> st;map<pair>,int> mp;int r[maxn],rn;int ans[maxn];int main(){    scanf("%d",&n);    for(int i=0;i<n scanf r sort rn="unique(r,r+rn)-r;" for i="0;i<n;i++)" int id="lower_bound(r,r+rn,a[i])-r;" b lis="1;" if v1 v2 f1 else p1="lower_bound(v1,v1+n1,a[i])-v1;" n1 p2="lower_bound(v2,v2+n2,b[i])-v2;" n2 f2 x="i,y=n-1-i;" ans mp printf putchar return>  <br>  <br>  <p></p>  <p><br> </p>  <p><br> </p>  <p><br> </p> </n></pair></int></map></set></vector></algorithm></cstring></cstdio></iostream>
    로그인 후 복사
    본 웹사이트의 성명
    본 글의 내용은 네티즌들의 자발적인 기여로 작성되었으며, 저작권은 원저작자에게 있습니다. 본 사이트는 이에 상응하는 법적 책임을 지지 않습니다. 표절이나 침해가 의심되는 콘텐츠를 발견한 경우 admin@php.cn으로 문의하세요.

    핫 AI 도구

    Undresser.AI Undress

    Undresser.AI Undress

    사실적인 누드 사진을 만들기 위한 AI 기반 앱

    AI Clothes Remover

    AI Clothes Remover

    사진에서 옷을 제거하는 온라인 AI 도구입니다.

    Undress AI Tool

    Undress AI Tool

    무료로 이미지를 벗다

    Clothoff.io

    Clothoff.io

    AI 옷 제거제

    Video Face Swap

    Video Face Swap

    완전히 무료인 AI 얼굴 교환 도구를 사용하여 모든 비디오의 얼굴을 쉽게 바꾸세요!

    뜨거운 도구

    메모장++7.3.1

    메모장++7.3.1

    사용하기 쉬운 무료 코드 편집기

    SublimeText3 중국어 버전

    SublimeText3 중국어 버전

    중국어 버전, 사용하기 매우 쉽습니다.

    스튜디오 13.0.1 보내기

    스튜디오 13.0.1 보내기

    강력한 PHP 통합 개발 환경

    드림위버 CS6

    드림위버 CS6

    시각적 웹 개발 도구

    SublimeText3 Mac 버전

    SublimeText3 Mac 버전

    신 수준의 코드 편집 소프트웨어(SublimeText3)

    HTML은 초보자를 위해 쉽게 배우나요? HTML은 초보자를 위해 쉽게 배우나요? Apr 07, 2025 am 12:11 AM

    HTML은 간단하고 배우기 쉽고 결과를 빠르게 볼 수 있기 때문에 초보자에게 적합합니다. 1) HTML의 학습 곡선은 매끄럽고 시작하기 쉽습니다. 2) 기본 태그를 마스터하여 웹 페이지를 만들기 시작하십시오. 3) 유연성이 높고 CSS 및 JavaScript와 함께 사용할 수 있습니다. 4) 풍부한 학습 리소스와 현대 도구는 학습 과정을 지원합니다.

    HTML, CSS 및 JavaScript의 역할 : 핵심 책임 HTML, CSS 및 JavaScript의 역할 : 핵심 책임 Apr 08, 2025 pm 07:05 PM

    HTML은 웹 구조를 정의하고 CSS는 스타일과 레이아웃을 담당하며 JavaScript는 동적 상호 작용을 제공합니다. 세 사람은 웹 개발에서 의무를 수행하고 화려한 웹 사이트를 공동으로 구축합니다.

    HTML의 시작 태그의 예는 무엇입니까? HTML의 시작 태그의 예는 무엇입니까? Apr 06, 2025 am 12:04 AM

    anexampleStartingtaginhtmlis, whithbeginsaparagraph.startingtagsareessentialinhtmlastheyinitiate rements, definetheirtypes, andarecrucialforstructurituringwebpages 및 smanstlingthedom.

    HTML, CSS 및 JavaScript 이해 : 초보자 안내서 HTML, CSS 및 JavaScript 이해 : 초보자 안내서 Apr 12, 2025 am 12:02 AM

    WebDevelopmentReliesonHtml, CSS 및 JavaScript : 1) HtmlStructuresContent, 2) CSSSTYLESIT, 및 3) JAVASCRIPTADDSINGINTERACTIVITY, BASISOFMODERNWEBEXPERIENCES를 형성합니다.

    웹 주석에서 y 축 위치의 적응 형 레이아웃을 구현하는 방법은 무엇입니까? 웹 주석에서 y 축 위치의 적응 형 레이아웃을 구현하는 방법은 무엇입니까? Apr 04, 2025 pm 11:30 PM

    웹 주석 기능에 대한 Y 축 위치 적응 알고리즘이 기사는 Word 문서와 유사한 주석 기능을 구현하는 방법, 특히 주석 간격을 다루는 방법을 모색합니다 ...

    Gitee Pages 정적 웹 사이트 배포 실패 : 단일 파일 문제를 해결하고 해결하는 방법 404 오류? Gitee Pages 정적 웹 사이트 배포 실패 : 단일 파일 문제를 해결하고 해결하는 방법 404 오류? Apr 04, 2025 pm 11:54 PM

    GiteEpages 정적 웹 사이트 배포 실패 : 404 오류 문제 해결 및 해결시 Gitee ...

    CSS3 및 JavaScript를 사용하여 클릭 후 주변 사진을 흩어지고 확대하는 효과를 얻는 방법은 무엇입니까? CSS3 및 JavaScript를 사용하여 클릭 후 주변 사진을 흩어지고 확대하는 효과를 얻는 방법은 무엇입니까? Apr 05, 2025 am 06:15 AM

    이미지를 클릭 한 후 주변 이미지를 산란 및 확대하는 효과를 얻으려면 많은 웹 디자인이 대화식 효과를 달성해야합니다. 특정 이미지를 클릭하여 주변을 만들 수 있습니다 ...

    HTML, CSS 및 JavaScript : 웹 개발자를위한 필수 도구 HTML, CSS 및 JavaScript : 웹 개발자를위한 필수 도구 Apr 09, 2025 am 12:12 AM

    HTML, CSS 및 JavaScript는 웹 개발의 세 가지 기둥입니다. 1. HTML은 웹 페이지 구조를 정의하고 등과 같은 태그를 사용합니다. 2. CSS는 색상, 글꼴 크기 등과 같은 선택기 및 속성을 사용하여 웹 페이지 스타일을 제어합니다.

    See all articles