·¶ÎÄ ·¶Àý Ö¸µ¼ ѧϰ
cout << endl; return 0; } ÊäÈë: 3
Êä³ö: 17 24 1 8 15 3. #include
using namespacestd;
int n, s,a[100005], t[100005], i; void mergesort(intl, int r){ if (l == r)
return; int mid = (l + r) / 2; int p = l; int i = l; int j = mid + 1£» mergesort (l, mid); mergesort (mid + 1, r); while (i <= mid && j<= r){
if (a[j] < a[i]){ ¨C i+1;
a[j]; p++; j++;
} else {
a[i];
i++;
} }
while (i <= mid){
word°æ±¾ÕûÀí·ÖÏí
s += mid t[p] = t[p] = p++;
·¶ÎÄ ·¶Àý Ö¸µ¼ ѧϰ
t[p] = a[i]; p++; i++; }
while (j <= r){
t[p] = a[j]; p++; j++; }
for (i = l; i <= r; i++ )
a[i] = t[i]; }
int main() { cin >> n;
for (i = 1; i <= n; i++) cin>> a[i]; mergesort (1, n); cout << s << endl; return 0; } ÊäÈë: 6
2 6 3 4 5 1 Êä³ö: 8 4. #include
using namespacestd; int main() { int n, m; cin >> n >> m; int x = 1; int y = 1; int dx = 1; int dy = 1; int cnt = 0;
word°æ±¾ÕûÀí·ÖÏí
·¶ÎÄ ·¶Àý Ö¸µ¼ ѧϰ
while (cnt != 2) { cnt = 0; x = x + dx; y = y + dy;
if (x == 1 || x == n) { ++cnt; dx = -dx; }
if (y == 1 || y == m) { ++cnt; dy = -dy; } }
cout << x << \ return 0; }
ÊäÈë1: 4 3
Êä³ö1: 1 3 (2 ·Ö) ÊäÈë2: 2017 1014 Êä³ö2: 2017 1 (3 ·Ö) ÊäÈë3: 987 321 Êä³ö3: 1 321 (3·Ö)
Îå¡¢ÍêÉÆ³ÌÐò£¨¹² 2 Ì⣬ÿÌâ 14 ·Ö£¬¹²¼Æ 28 ·Ö£© 1.
´óÕûÊý³ý·¨£º¸ø¶¨Á½¸öÕýÕûÊýpºÍq£¬ÆäÖÐp²»³¬¹ý10100£¬q²»³¬¹ý100000£¬Çóp³ýÒÔqµÄÉ̺ÍÓàÊý¡££¨µÚÒ»¿Õ2·Ö£¬ÆäÓà3·Ö£©?
ÊäÈ룺µÚÒ»ÐÐÊÇpµÄλÊýn£¬µÚ¶þÐÐÊÇÕýÕûÊýp£¬µÚÈýÐÐÊÇÕýÕûÊýq¡£ Êä³ö£ºÁ½ÐУ¬·Ö±ðÊÇp³ýÒÔqµÄÉ̺ÍÓàÊý¡£ #include
using namespacestd; int p[100]; int n, i, q,rest; char c; int main(){
cin >> n;
word°æ±¾ÕûÀí·ÖÏí
·¶ÎÄ ·¶Àý Ö¸µ¼ ѧϰ
for (i = 0; i < n; i++){
cin >> c;
p[i] = c ¨C ¡®0¡¯£» } cin >> q; rest = p[0]; i = 1;
while (rest< q && i < n){
rest = rest * 10 + p[i]; i++; }
if (rest < q)
cout << 0 < cout << rest / q; while (i < n){ rest = rest % q * 10 + p[i]; i++; cout<< rest / q; } cout << endl; } cout << rest % q<< endl; return 0; } 2. ×·¾¶£º¸ø¶¨Ò»¸öÓÐÏòÎ廷ͼ£¬Ã¿Ìõ±ß³¤¶ÈΪ1£¬ÇóͼÖеÄ×·¾¶³¤¶È¡££¨µÚÎå¿Õ 2 ·Ö£¬ÆäÓà 3 ·Ö£© ÊäÈ룺µÚÒ»ÐÐÊǽáµãÊýn£¨²»³¬¹ý100£©ºÍ±ßÊým£¬½ÓÏÂÀ´mÐУ¬Ã¿ÐÐÁ½¸öÕûÊýa,b£¬±íʾ´Ó½áµãaµ½½áµãbÓÐÒ»ÌõÓÐÏò±ß¡£½áµã±êºÅ´Ó0µ½(n-1)¡£ Êä³ö£º×·¾¶³¤¶È¡£ Ìáʾ£ºÏȽøÐÐÍØÆËÅÅÐò£¬È»ºó°´ÕÕÍØÆËÅÅÐò¼ÆËã×·¾¶¡£ #include using namespacestd; word°æ±¾ÕûÀí·ÖÏí ·¶ÎÄ ·¶Àý Ö¸µ¼ ѧϰ int n, m, i, j,a, b, head, tail, ans; int graph[100][100]; // ÓÃÁÚ½Ó¾ØÕó´æ´¢Í¼ int degree[100]; // ¼Ç¼ÿ¸ö½áµãµÄÈë¶È int len[100]; // ¼Ç¼ÒÔ¸÷½áµãΪÖÕµãµÄ×·¾¶³¤¶È int queue[100]; // ´æ·ÅÍØÆËÅÅÐò½á¹û int main() { cin >> n >> m; for (i = 0; i < n; i++) for (j = 0;j < n; j++) graph[i][j]= 0; for (i = 0; i < n; i++) degree[i] =0; for (i = 0; i < m; i++){ cin>> a >>b; graph[a][b]= 1; degree[b]++; } tail = 0; for (i = 0; i < n; i++) if (degree[i] == 0){ queue[tail]= i; tail++; } head = 0; while (tail < n-1){ for (i = 0;i < n; i++) if(graph[queue[head]] [i] == 1){ degree[i]--; if(degree[i] == 0){ queue[tail]= i; tail++; } } head++; word°æ±¾ÕûÀí·ÖÏí
Ïà¹ØÍÆ¼ö£º