Codeforces Round #271 (Div. 2) Solution Report_html/css_WEB-ITnose
Question address: http://codeforces.com/contest/474
Question A: Keyboard
Simulating water question.
The code is as follows:
#include <iostream>#include <cstdio>#include <string>#include <cstring>#include <stdlib.h>#include <math.h>#include <ctype.h>#include <queue>#include <map>#include <set>#include <algorithm>using namespace std;#define LL __int64char s[]={"qwertyuiopasdfghjkl;zxcvbnm,./"};int main(){ int i, x, j, len; char c, s1[200]; scanf("%c",&c); if(c=='L') x=1; else x=-1; scanf("%s",s1); len=strlen(s1); for(i=0;i<len;i++) { for(j=0;;j++) { if(s[j]==s1[i]) { printf("%c", s[j+x]); break; } } } return 0;}
Question B: Worms
Water question. .
The code is as follows:
#include <iostream>#include <cstdio>#include <string>#include <cstring>#include <stdlib.h>#include <math.h>#include <ctype.h>#include <queue>#include <map>#include <set>#include <algorithm>using namespace std;#define LL __int64int dp[1100000];int main(){ int n, m, i, j, sum=0, x; scanf("%d",&n); for(i=0;i<n;i++) { scanf("%d",&x); for(j=sum;j<sum+x;j++) { dp[j]=i; } sum+=x; } scanf("%d",&m); while(m--) { scanf("%d",&x); printf("%d\n",dp[x-1]+1); } return 0;}
Question C: Captain Marmot
Violent enumeration, a total of 4*4*4*4 In each case, determine whether it is a square. I actually always thought it was a rectangle. .
Judgment method: Calculate the four sides and two diagonals respectively. Then sort, the 4 small ones must be sides, and the 2 big ones are diagonals, and then determine whether the sides are equal, whether the diagonals are all equal, and whether the diagonal is sqrt(2) times the side (the best here Use the square to determine whether it is 2 times). Then just find the output with the fewest moves.
The code is as follows:
#include <iostream>#include <cstdio>#include <string>#include <cstring>#include <stdlib.h>#include <math.h>#include <ctype.h>#include <queue>#include <map>#include <set>#include <algorithm>using namespace std;#define LL __int64const int mod=1e9+7;struct node{ LL x, y;}t1[5], t2[5], fei[5];node solve(node x, node y, int z){ node t; t=x; int i; for(i=0;i<z;i++) { x.x=y.y-t.y+y.x; x.y=t.x-y.x+y.y; t=x; } return t;}LL dist(node a, node b){ LL x=a.x-b.x; LL y=a.y-b.y; return x*x+y*y;}bool judge(){ int i, j; LL d[6]; d[0]=dist(fei[0],fei[1]); d[1]=dist(fei[1],fei[2]); d[2]=dist(fei[2],fei[3]); d[3]=dist(fei[3],fei[0]); d[4]=dist(fei[0],fei[2]); d[5]=dist(fei[1],fei[3]); sort(d,d+6); if(d[0]==0) return 0; if(d[0]==d[1]&&d[1]==d[2]&&d[2]==d[3]&&d[4]==2*d[0]&&d[4]==d[5]) return 1; return 0;}int main(){ int t, i, j, k, h, min1; scanf("%d",&t); while(t--) { min1=20; for(i=0;i<4;i++) { scanf("%I64d%I64d%I64d%I64d",&t1[i].x,&t1[i].y,&t2[i].x,&t2[i].y); } for(i=0;i<4;i++) { fei[0]=solve(t1[0],t2[0],i); for(j=0;j<4;j++) { fei[1]=solve(t1[1],t2[1],j); for(k=0;k<4;k++) { fei[2]=solve(t1[2],t2[2],k); for(h=0;h<4;h++) { fei[3]=solve(t1[3],t2[3],h); if(judge()) { min1=min(min1,i+j+k+h); } } } } } if(min1==20) puts("-1"); else printf("%d\n",min1); } return 0;}
Question D: Flowers
DP, again a water question. . You can think of it this way:
There are only two situations for the nth one. If the nth one is R, then the number of situations is dp[n-1]. If the nth one is W, since W can only be k consecutive times, so the n-k 1st to nth ones must all be W, then the number of situations at this time is dp[n-k]. So the state transition equation is:
dp[n]=dp[n-1] dp[n-k].
Then use an array to save the prefix sum.
The code is as follows:
#include <iostream>#include <cstdio>#include <string>#include <cstring>#include <stdlib.h>#include <math.h>#include <ctype.h>#include <queue>#include <map>#include <set>#include <algorithm>using namespace std;#define LL __int64const int mod=1e9+7;LL dp[110000], sum[110000];int main(){ int i, j, n, k, a, b; LL x=0; sum[0]=0; dp[0]=0; scanf("%d%d",&n,&k); for(i=1;i<=k-1;i++) dp[i]=1; dp[k]=2; for(i=k+1;i<=100000;i++) { dp[i]=dp[i-k]+dp[i-1]; dp[i]%=mod; } for(i=1;i<=100000;i++) { sum[i]=(sum[i-1]+dp[i])%mod; } while(n--) { scanf("%d%d",&a,&b); printf("%I64d\n",(sum[b]+mod-sum[a-1])%mod); } return 0;}

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics



In PHP, round means "rounding" and is a built-in function that converts floating point numbers into integers. This function can round floating point numbers and return an integer value of type float. The syntax is "round(number, precision,mode);".

The round() function is a very useful function in the PHP number formatting library, which can round floating point numbers to a specified number of decimal places. However, since PHP's division operation may suffer from infinite decimals or loss of precision, rounding of the divisor is also necessary. Next, we will explain in detail how to use PHP's round() function to divide and round.

How to use the ROUND function in MySQL to intercept the number of decimal places. In MySQL, you can use the ROUND function to intercept the number of decimal places. The ROUND function rounds a number to a specified number of decimal places. The following will introduce you to the use of ROUND function in detail and provide code examples. Syntax: ROUND(X,D)X represents the number to be rounded, and D represents the number of decimal places to be retained. Example of using the ROUND function to intercept the number of decimal places: Suppose there is a table named produc

This article will share the entire process of training ChatGPT (the latest GPT-4 model version) and generating reports, and discuss the common problems that exist in the use of ChatGPT, and how to use ChatGPT to maximize learning and work efficiency. The following is the entire process of generating an AI safety report. Infrastructure topic selection A high-quality topic selection can help academic researchers quickly determine the entry point of the report, guide readers to capture the main theme of the report, and make the entire report present a clearer structure and logic. By introducing the background of the report or providing keywords and overview to ChatGPT, ChatGPT can generate topic selections in a few seconds for researchers' reference. When we ask questions, we can ask ChatGPT to generate multiple topic choices at the same time, which helps

MySQL and Oracle: Comparison of Support for Analysis and Reporting Functions In the modern data-driven world, as enterprise data continues to grow, the demand for data analysis and reporting functions is also increasing. As the two most popular relational database management systems (RDBMS), MySQL and Oracle have high support performance in this regard. This article will compare them in terms of their support for data analysis and reporting functions, and demonstrate the differences through code examples. First, let’s take a look at MySQL’s data analysis

When hundreds of industry-oriented AI large models appear, the data center hosting the large models is quietly changing. Large models require large computing power. On the one hand, data centers will provide diverse computing comprehensive capabilities as the computing power base for digital transformation to meet the intelligent needs of different industries; on the other hand, data centers continue to improve energy use efficiency, which requires A better computing architecture and lower energy consumption generate greater computing power, which not only achieves green and low carbon itself, but also empowers the intelligent transformation of other industries and promotes the carbon reduction of the whole society. According to data from the Ministry of Industry and Information Technology, the total number of data center racks in use in my country will exceed 5.9 million standard racks in 2022, the number of servers will be approximately 20 million, and the average annual growth rate of data center storage capacity will exceed 50%. At the same time, throughout the

Kuaishou releases an annual report for everyone to read every year, so what do you think of this year’s annual report? Users can search for annual memories in the search bar. This introduction to the 2023 annual report viewing method can tell you how to operate it. The following is a detailed introduction, come and take a look! Kuaishou usage tutorial: Where can I exchange Kuaishou coins for Kuaishou Express version? Answer: Search for annual memories in the search bar. Specific introduction: 1. First click on the search bar above, enter annual memories, and then click to participate. 2. After entering, click Open Now below. 3. Swipe down to turn pages. 4. At the end, you can have the function of publishing works with one click to share them.

Here we will see how to write a one line C function that can round floating point numbers. In order to solve this problem, we have to follow the following steps. Get a number If the number is positive, add 0.5 otherwise, subtract 0.5 Use type conversion to convert the floating point value to an integer Example #include<stdio.h> intmy_round(floatnumber){ return(int)(number<0?number- 0.5:number+0.5);}intmain(){ 
