日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

国庆5

發布時間:2025/4/16 编程问答 29 豆豆
生活随笔 收集整理的這篇文章主要介紹了 国庆5 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

Codeforces 1060 b

?

You are given a positive integer?nn.

Let?S(x)S(x)?be sum of digits in base 10 representation of?xx, for example,?S(123)=1+2+3=6S(123)=1+2+3=6,?S(0)=0S(0)=0.

Your task is to find two integers?a,ba,b, such that?0a,bn0≤a,b≤n,?a+b=na+b=n?and?S(a)+S(b)S(a)+S(b)?is the largest possible among all such pairs.


In the first example, you can choose, for example,?a=17a=17?and?b=18b=18, so that?S(17)+S(18)=1+7+1+8=17S(17)+S(18)=1+7+1+8=17. It can be shown that it is impossible to get a larger answer.

In the second test example, you can choose, for example,?a=5000000001a=5000000001?and?b=4999999999b=4999999999, with?S(5000000001)+S(4999999999)=91S(5000000001)+S(4999999999)=91. It can be shown that it is impossible to get a larger answer.

35 Output 17 Input 10000000000 Output 91

該題:
10的12 次方,不能用ll,只能用char 數組。貪心思想:九越多越好,把這個數分成比他少一位數,都是9的數例如:
100 :99 1;
也就是從字符串的最后開始往前找(我的做法,不知道從前往后行不行)如果這個字符比九小,例如 23,走到3,發現比9小,那么另一個數這一位就是4(因為你是想把3這一位拆乘9)2就要-1成為1。
做法中沒有討論遇到108 - 9 的情況,因為這樣做每一步都能保證運行到該行時他的值都大于0,最后加上最開頭以為數字-‘0’;

#include <iostream> #include <algorithm> #include<cstdio> #include<stack> #include <deque> #include <cstdlib> #include <cstring> #include <string> #include <map> #include <deque> #include <vector> using namespace std; typedef long long ll; map<int,int>mp; int main() {char a[100];int i,ans=0;scanf("%s",a);int a1=strlen(a);for(i=a1-1;i>=1;i--){if(a[i]=='9'){ans+=9;}else{ans+=a[i]-'0'+10;a[i-1]-=1;}}ans+=a[i]-'0';printf("%d\n",ans);}

?

Codeforces 712 c

?

一個等邊三角形,由大的變成小的要最少多少步,而且保證每一步都是三角形。

該題應該考慮從小加到大,因為這樣加的時候是可以有據可依的(保證是三角形):兩邊之和大于第三邊。然后再用貪心的思想,三個數輪著變成另外兩個數相加-1,保證這樣是步數最少的。

如果到了一個數大于要求的邊時,break,然后加2,因為要變成等邊三角形:

#include <iostream> #include <algorithm> #include<cstdio> #include<stack> #include <deque> #include <cstdlib> #include <cstring> #include <string> #include <map> #include <deque> #include <vector> using namespace std; typedef long long ll; map<int,int>mp; int main() {int a,b;scanf("%d%d",&a,&b);int x=b,y=b,z=b;int flag=1;int ans=0;while(1){if(x==a&&y==a&&z==a)break;if(flag==1){flag++;x=y+z-1;ans++;if(x>=a)break;}if(flag==2){ans++;flag++;y=x+z-1;if(y>=a)break;}if(flag==3){ans++;flag=1;z=x+y-1;if(z>=a)break;}}printf("%d\n",ans+2);}

?

Codeforces 712 B

?

?這個題就是一個人能上下左右走,最好要回到原點,讓你改變他的路徑例如,樣例給的lruu,你要回去所以u要變成d,問最少要變幾次。

這個題可以考慮對稱,從原點開始走,最后回到原點。

左右對稱,抵消掉,剩下的就是左右的差,上下的差,如果他們的和是偶數,則能改變,否在無論如何多一個無法回到原點。

#include <iostream> #include <algorithm> #include<cstdio> #include<stack> #include <deque> #include <cstdlib> #include <cstring> #include <string> #include <map> #include <deque> #include <vector> using namespace std; typedef long long ll; map<int,int>mp; int main() {char a[100100];int i,j,ge1=0,ge2=0;scanf("%s",a);int a1=strlen(a);for(i=0; i<=a1-1; i++){if(a[i]=='L')ge1++;if(a[i]=='R')ge1--;if(a[i]=='U')ge2++;if(a[i]=='D')ge2--;}if((abs(ge1)+abs(ge2))%2!=0)printf("-1\n");elseprintf("%d\n",(abs(ge1)+abs(ge2))/2);}

?

轉載于:https://www.cnblogs.com/bhd123/p/9746792.html

總結

以上是生活随笔為你收集整理的国庆5的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。