Gym100735D- Triangle Formation Gym100735E - Restore Gym100735G - LCS Revised Gym100735I - Yet another A + B(大数,Java) KTU Programming Camp (Day 1) Lithuania, Birˇstonas, August 19, 2015
2018-01-22 15:59
549 查看
日常训练题解。。。
YouaregivenNwoodensticks.Yourtaskistodeterminehowmanytrianglescanbemadefromthegivenstickswithoutbreakingthem.Eachstickcanbeusedinatmostonetriangle.
Input
ThefirstlineofeachtestcasecontainsthenumberofsticksN.(1 ≤ N ≤ 15)
ThesecondlineofeachtestcasecontainsNintegerslenithatarethelengthsofthesticks.(1 ≤ leni ≤ 109).
Output
OutputsingleintegerR–themaximalnumberoftriangles.
Example
Input
Output
Input
Output
Input
Output
暴搜就可以了。。。
代码:
GivenamatrixAofsizeN * N.Therowsarenumberedfrom0toN-1,thecolumnsarenumberedfrom0toN-1.Inthismatrix,thesumsofeachrow,thesumsofeachcolumn,andthesumofthetwodiagonalsareequal.
Forexample,amatrixwithN = 3:
Thesumsofeachrow:
2 + 9 + 4 = 15
7 + 5 + 3 = 15
6 + 1 + 8 = 15
Thesumsofeachcolumn:
2 + 7 + 6 = 15
9 + 5 + 1 = 15
4 + 3 + 8 = 15
Thesumsofeachdiagonal:
2 + 5 + 8 = 15
4 + 5 + 6 = 15
Asyoucannotice,allsumsareequalto15.
However,allthenumbersinthemaindiagonal(themaindiagonalconsistsofcells(i, i))havebeenremoved.Yourtaskistorecoverthesecells.
Input
Thefirstlinecontainsthedimensionofthematrix,n(1 ≤ n ≤ 100).
Thefollowingnlinescontainnintegerseach,withremovednumbersdenotedby0,andallothernumbers - 1012 ≤ Aij ≤ 1012.
Output
Therestoredmatrixshouldbeoutputtedinasimilarformat,withnlinesconsistingofnintegerseach.
Example
Input
Output
ThelongestcommonsubsequenceisawellknownDPproblem:giventwostringsAandB,onehastocomputethemaximumlengthofasubsequencethat'scommontobothAandB.
InthisparticularproblemweworkwithstringsAandBformedonlyby0and1,havingthesamelength.You'regivenastringAoflengthn.IterateallstringsBpossible.Thereare2nofthem.Calculate,foreachstringB,thelongestcommonsubsequenceofAandB.Then,outputtheminimumlengthobtained.
ThefirstandtheonlylineoftheinputcontainsstringA,formedonlyby0and1.It'sguaranteedthatthelengthisbetween1and105.
Outputasinglenumber-therequestedlength.
Input
Output
超级无敌大水题,直接找0和1哪个少就可以。。。
代码:
Youaregiventhreenumbers.IsthereawaytoreplacevariablesA,BandCwiththesenumberssotheequalityA+B=Ciscorrect?
Input
TherearethreenumbersX1,X2andX3(1≤Xi≤10100),eachonaseparatelineofinput.
Output
either"YESifthereisawaytosubstitutevariablesA,BandCwithgivennumberssotheequalityiscorrect,or"NO"otherwise.
Examples
input
123
output
YES
input
124
output
YES
input
135
output
NO
大数计算,给出的数任选2个相加能否等于第三个数或者重复选1个数相加是否等于剩下的2个中的1个,因为是大数,所以直接用Java写的,偷懒专用,哈哈哈哈哈哈。
代码:
溜了溜了。。。
D-TriangleFormation
YouaregivenNwoodensticks.Yourtaskistodeterminehowmanytrianglescanbemadefromthegivenstickswithoutbreakingthem.Eachstickcanbeusedinatmostonetriangle.Input
ThefirstlineofeachtestcasecontainsthenumberofsticksN.(1 ≤ N ≤ 15)
ThesecondlineofeachtestcasecontainsNintegerslenithatarethelengthsofthesticks.(1 ≤ leni ≤ 109).
Output
OutputsingleintegerR–themaximalnumberoftriangles.
Example
Input
2 11
Output
0
Input
3 222
Output
1
Input
6 223456
Output
2
暴搜就可以了。。。
代码:
1#include<cstring> 2#include<cstdio> 3#include<iostream> 4#include<algorithm> 5usingnamespacestd; 6inta[50],flag[50]; 7intmain(){ 8intn; 9while(~scanf("%d",&n)){ 10memset(flag,0,sizeof(flag)); 11for(inti=0;i<n;i++){ 12scanf("%d",&a[i]); 13flag[i]=1; 14} 15sort(a,a+n); 16if(n<=2)printf("0\n"); 17else{ 18intnum=0; 19for(inti=0;i<n;i++){ 20for(intj=0;j<n;j++){ 21for(intk=0;k<n;k++){ 22if(i!=j&&i!=k&&j!=k&&flag[i]==1&&flag[j]==1&&flag[k]==1&&a[i]+a[j]>a[k]&&a[i]+a[k]>a[j]&&a[k]+a[j]>a[i]){ 23num++;flag[i]=0;flag[j]=0;flag[k]=0; 24} 25elsecontinue; 26} 27} 28} 29printf("%d\n",num); 30} 31} 32return0; 33}
E-Restore
GivenamatrixAofsizeN * N.Therowsarenumberedfrom0toN-1,thecolumnsarenumberedfrom0toN-1.Inthismatrix,thesumsofeachrow,thesumsofeachcolumn,andthesumofthetwodiagonalsareequal.Forexample,amatrixwithN = 3:
Thesumsofeachrow:
2 + 9 + 4 = 15
7 + 5 + 3 = 15
6 + 1 + 8 = 15
Thesumsofeachcolumn:
2 + 7 + 6 = 15
9 + 5 + 1 = 15
4 + 3 + 8 = 15
Thesumsofeachdiagonal:
2 + 5 + 8 = 15
4 + 5 + 6 = 15
Asyoucannotice,allsumsareequalto15.
However,allthenumbersinthemaindiagonal(themaindiagonalconsistsofcells(i, i))havebeenremoved.Yourtaskistorecoverthesecells.
Input
Thefirstlinecontainsthedimensionofthematrix,n(1 ≤ n ≤ 100).
Thefollowingnlinescontainnintegerseach,withremovednumbersdenotedby0,andallothernumbers - 1012 ≤ Aij ≤ 1012.
Output
Therestoredmatrixshouldbeoutputtedinasimilarformat,withnlinesconsistingofnintegerseach.
Example
Input
3 094 703 610
Output
294 753 618 这个题有一个地方有点坑,就是如果一行里面有两个0,因为只有对角线的挖掉了,所以直接竖着算这一排的就可以。其他的没了。 代码:
1#include<iostream> 2#include<cstring> 3#include<cstdio> 4#include<algorithm> 5usingnamespacestd; 6typedeflonglongll; 7lla[105][105]; 8intmain(){ 9intn; 10while(~scanf("%d",&n)){ 11llcnt=0; 12for(inti=0;i<n;i++){ 13for(intj=0;j<n;j++){ 14scanf("%lld",&a[i][j]); 15cnt+=a[i][j]; 16} 17} 18cnt/=n-1;inti,j;//算那个相等的值 19for(i=0;i<n;i++){ 20llnum=0;intflag,ret=0; 21for(j=0;j<n;j++){ 22num+=a[i][j]; 23if(a[i][j]==0){flag=j;ret++;} 24} 25if(ret>1){//如果这一排有多于1个0 26llqwe=0; 27for(intk=0;k<n;k++)qwe+=a[k][i]; 28a[i][i]=cnt-qwe; 29} 30elseif(num!=cnt)a[i][flag]=cnt-num; 31} 32for(inti=0;i<n;i++){ 33for(intj=0;j<n;j++){ 34printf("%lld",a[i][j]); 35if(j!=n-1)printf(""); 36elseprintf("\n"); 37} 38} 39} 40return0; 41}
G-LCSRevised
ThelongestcommonsubsequenceisawellknownDPproblem:giventwostringsAandB,onehastocomputethemaximumlengthofasubsequencethat'scommontobothAandB.
InthisparticularproblemweworkwithstringsAandBformedonlyby0and1,havingthesamelength.You'regivenastringAoflengthn.IterateallstringsBpossible.Thereare2nofthem.Calculate,foreachstringB,thelongestcommonsubsequenceofAandB.Then,outputtheminimumlengthobtained.
Input
ThefirstandtheonlylineoftheinputcontainsstringA,formedonlyby0and1.It'sguaranteedthatthelengthisbetween1and105.
Output
Outputasinglenumber-therequestedlength.
Example
Input
101010
Output
3
超级无敌大水题,直接找0和1哪个少就可以。。。
代码:
1#include<iostream>
2#include<cstring>
3#include<cstdio>
4usingnamespacestd;
5constintN=1e6+10;
6chara
;
7intmain(){
8while(~scanf("%s",a)){
9intlen=strlen(a);
10intans,num1=0,num2=0;
11for(inti=0;i<len;i++){
12if(a[i]=='1')num1++;
13elsenum2++;
14}
15ans=min(num1,num2);
16printf("%d\n",ans);
17}
18return0;
19}
I-YetanotherA+B
Youaregiventhreenumbers.IsthereawaytoreplacevariablesA,BandCwiththesenumberssotheequalityA+B=Ciscorrect?Input
TherearethreenumbersX1,X2andX3(1≤Xi≤10100),eachonaseparatelineofinput.
Output
either"YESifthereisawaytosubstitutevariablesA,BandCwithgivennumberssotheequalityiscorrect,or"NO"otherwise.
Examples
input
123
output
YES
input
124
output
YES
input
135
output
NO
大数计算,给出的数任选2个相加能否等于第三个数或者重复选1个数相加是否等于剩下的2个中的1个,因为是大数,所以直接用Java写的,偷懒专用,哈哈哈哈哈哈。
代码:
1importjava.util.Scanner;
2
3publicclassBigInteger{
4privatestaticScannercin;
5
6publicstaticvoidmain(String[]args){
7cin=newScanner(System.in);
8java.math.BigIntegera;
9java.math.BigIntegerb;
10java.math.BigIntegerc;
11a=cin.nextBigInteger();
12b=cin.nextBigInteger();
13c=cin.nextBigInteger();
14if((a.add(b)).compareTo(c)==0)System.out.println("YES\n");
15elseif((a.add(c)).compareTo(b)==0)System.out.println("YES\n");
16elseif((b.add(c)).compareTo(a)==0)System.out.println("YES\n");
17elseif((a.add(a)).compareTo(b)==0||(a.add(a)).compareTo(c)==0)System.out.println("YES\n");
18elseif((b.add(b)).compareTo(a)==0||(b.add(b)).compareTo(c)==0)System.out.println("YES\n");
19elseif((c.add(c)).compareTo(a)==0||(c.add(c)).compareTo(b)==0)System.out.println("YES\n");
20elseSystem.out.println("NO\n");
21}
22}
溜了溜了。。。
相关文章推荐
- Java大数简单题---Yet another A + B
- Yet another A + B——KTU Programming Camp (Day 1) I题
- Own your Android! Yet Another Universal Root CVE-2015-3636 (中文翻译) (3)
- Yet Another Java Service Wrapper
- Own your Android! Yet Another Universal Root CVE-2015-3636 (中文翻译) (2)
- 【推导】【构造】Petrozavodsk Summer Training Camp 2015 Day 2: Xudyh (TooSimple) Contest, Saturday, August 22, 2015 Problem G. Travelling Salesman Problem
- Own your Android! Yet Another Universal Root CVE-2015-3636 (中文翻译) (1)
- Yet Another Java Service Wrapper
- Java day 18-19
- (45)21.4.3 并发 练习 19---Java编程思想之并发笔记
- Java——Day 01
- 19. JAVA 网络编程 Part 1 (IP与InetAddress类、URL与URLConnection类、URLEncoder与URLDecoder类、TCP&UDP)---- 学习笔记
- ZOJ 3610 Yet Another Story of Rock-paper-scissors
- Java 19
- LeetCode 19 Remove Nth Node From End of List (C,C++,Java,Python)
- zoj3759(待解决+算法木有问题+but需要java大数)
- 2015第六届蓝桥杯 07 加法变乘法 (java)
- Thursday, August 16, 2012How to sort ArrayList in java - List Sorting - Ascending Descending Order
- Java串口助手(程序源码) 分类: Java 2015-07-30 10:13 16人阅读 评论(0) 收藏
- 21天精通java基础之Day17生产者消费者例题