Toggle menu
Toggle personal menu
Not logged in
Your IP address will be publicly visible if you make any edits.

1R/2016 07 06: Difference between revisions

From ZeroWiki
({CREATE})
 
No edit summary
Line 8: Line 8:
| 이름
| 이름
| 학번
| 학번
|-
| 박인서
| 15학번
|}
|}


= 코드 =
= 코드 =
== 박인서 ==
=== 아이디어 1 ===
#include <iostream>
#include <algorithm>
#include <vector>
bool cmp(int a, int b) {return a>b;}
int main() {
int TC;
int k;
std::cin>>TC;
for(k=1;k<=TC;k++){
int n,m;
std::vector<int> a;
std::cin>>n>>m;
for(int i=0;i<n;i++){
int t;
std::cin>>t;
a.push_back(t);
}
std::sort(a.begin(),a.end(),cmp);
int res=0;
for(int i=0;i<m;i++) res+=a[i];
std::cout<<"Case #"<<k<<std::endl<<res<<std::endl;
}
return 0;
}
=== 아이디어 2 ===
* 내일 짭니다.


= 아이디어 =
= 아이디어 =
== 박인서 ==
* 아이디어 1 : 내림차순으로 정렬 후 큰 것부터 더해나가는 방식
* 아이디어 2 : priority_queue 이용



Revision as of 08:27, 5 July 2016

오늘의 문제

공부

참가자

이름 학번
박인서 15학번

코드

박인서

아이디어 1

#include <iostream>
#include <algorithm>
#include <vector>

bool cmp(int a, int b) {return a>b;}

int main() {
	int TC;
	int k;
	std::cin>>TC;

	for(k=1;k<=TC;k++){
		int n,m;
		std::vector<int> a;
		std::cin>>n>>m;

		for(int i=0;i<n;i++){
			int t;
			std::cin>>t;
			a.push_back(t);
		}
		std::sort(a.begin(),a.end(),cmp);

		int res=0;
		for(int i=0;i<m;i++) res+=a[i];
		std::cout<<"Case #"<<k<<std::endl<<res<<std::endl;
	}

	return 0;
}

아이디어 2

  • 내일 짭니다.

아이디어

박인서

  • 아이디어 1 : 내림차순으로 정렬 후 큰 것부터 더해나가는 방식
  • 아이디어 2 : priority_queue 이용