Easy h-index

比赛题目:
http://acm.hdu.edu.cn/downloads/2018ccpc_hn.pdf

The h-index of an author is the largest h where he has at least h papers with citations not less than h.

Bobo has published many papers.
Given a0,a1,a2,…,an which means Bobo has published ai papers with citations exactly i, find the h-index of Bobo.

Input
The input consists of several test cases and is terminated by end-of-file.

The first line of each test case contains an integer n.
The second line contains (n+1) integers a0,a1,…,an.
Output
For each test case, print an integer which denotes the result.

Constraint

  • 1≤n≤2⋅105
  • 0≤ai≤109
  • The sum of n does not exceed 250,000.
    Sample Input
    1
    1 2
    2
    1 2 3
    3
    0 0 0 0
    Sample Output
    1
    2
    0

题目大意:
a[i]为发表篇数,i为引文篇数。
找出一个h,满足:至少有h篇且引文不低于h的论文

因为已知篇数,不低于,有这个关键词我们想到把循环倒着过来找。因为i是逐渐增大的,所以引文篇数也逐渐增大。

本题考点是一个简单的前缀和(是今天尝试在学的一个新东西orz)。

通过的代码如下:

#include<stdio.h>
#include<algorithm>
#include<string.h>
using namespace std;
int a[200010];
int main(){
int n;
while(scanf("%d",&n)!=EOF)
{
	int sum=0;
	for(int i=0;i<=n;i++)
	{
		scanf("%d",&a[i]);
	 }
	 for(int i=n;i>=0;i--)
	 {
	 	sum+=a[i];     //倒着加起来
	 	if(sum>=i)     //这个i就是要找的h
	 	{
	 		printf("%d\n",i);
	 		break;
		 }
	  }
	 
}
	return 0;
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
好的,这是一个简单的俄罗斯方块游戏的代码示例: ```c++ #include <iostream> #include <vector> #include <cstdlib> #include <ctime> #include <conio.h> #include <windows.h> using namespace std; const int ROW = 30; const int COL = 20; int score; int map[ROW][COL]; struct Point { int x, y; Point(int x = 0, int y = 0) :x(x), y(y) {} }; vector<Point> curShape; vector<vector<Point>> shapes; void initShapes() { shapes.push_back({ {0,0}, {0,1}, {0,2}, {0,3} }); shapes.push_back({ {0,0}, {0,1}, {0,2}, {1,2} }); shapes.push_back({ {0,0}, {0,1}, {1,0}, {1,1} }); shapes.push_back({ {0,0}, {0,1}, {0,2}, {1,1} }); shapes.push_back({ {0,0}, {0,1}, {1,1}, {1,2} }); shapes.push_back({ {0,0}, {1,0}, {1,1}, {2,1} }); shapes.push_back({ {0,1}, {1,1}, {2,0}, {2,1} }); } void newShape() { curShape.clear(); srand((unsigned)time(NULL)); int index = rand() % shapes.size(); for (int i = 0; i < 4; i++) { Point p = shapes[index][i]; curShape.push_back(Point(p.x + ROW / 2, p.y)); } } bool check(Point p) { if (p.x < 0 || p.x >= ROW || p.y >= COL) return false; if (map[p.x][p.y]) return false; return true; } bool isOver() { for (int i = 0; i < 4; i++) { if (!check(curShape[i])) return true; } return false; } void transform(Point& p) { int tmp = p.x; p.x = p.y; p.y = 3 - tmp; } void rotate() { Point center = curShape[1]; for (int i = 0; i < 4; i++) { if (i == 1) continue; int x = curShape[i].x - center.x; int y = curShape[i].y - center.y; Point t(x, y); transform(t); curShape[i].x = center.x + t.x; curShape[i].y = center.y + t.y; } } void updateMap() { for (int i = 0; i < 4; i++) { int x = curShape[i].x; int y = curShape[i].y; map[x][y] = 1; } } bool full(int r) { for (int c = 0; c < COL; c++) { if (map[r][c] == 0) return false; } return true; } void removeRow(int r) { for (int c = 0; c < COL; c++) { map[r][c] = 0; } for (int i = r; i >= 1; i--) { for (int c = 0; c < COL; c++) { map[i][c] = map[i - 1][c]; } } for (int c = 0; c < COL; c++) { map[0][c] = 0; } score++; } void checkFull() { for (int r = ROW - 1; r >= 0; r--) { if (full(r)) { removeRow(r); r++; } } } void refresh() { system("cls"); cout << "score: " << score << endl; for (int i = 0; i < ROW; i++) { for (int j = 0; j < COL; j++) { if (map[i][j]) cout << "*"; else cout << " "; } cout << endl; } } void moveLeft() { for (int i = 0; i < 4; i++) { Point p = curShape[i]; p.y--; if (!check(p)) { return; } } for (int i = 0; i < 4; i++) { curShape[i].y--; } } void moveRight() { for (int i = 0; i < 4; i++) { Point p = curShape[i]; p.y++; if (!check(p)) { return; } } for (int i = 0; i < 4; i++) { curShape[i].y++; } } void moveDown() { if (isOver()) { cout << "Game Over!" << endl; exit(0); } for (int i = 0; i < 4; i++) { Point p = curShape[i]; p.x++; if (!check(p)) { updateMap(); checkFull(); newShape(); return; } } for (int i = 0; i < 4; i++) { curShape[i].x++; } } int main() { initShapes(); newShape(); while (1) { refresh(); Sleep(300); if (_kbhit()) { int c = _getch(); switch (c) { case 'a': moveLeft(); break; case 'd': moveRight(); break; case 'w': rotate(); break; case 's': moveDown(); break; default: break; } } else { moveDown(); } } return 0; } ``` 注意:此代码是通过 C++ 开发,需要在 Windows 系统下使用。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值